Sunday 20 September 2015

Garbage Collection

Garbage collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects.

An in use object, or a referenced object (program still maintains a pointer to that object).

An unused object, or unreferenced object (no longer referenced by any part of program). So the memory used by an unreferenced object can be reclaimed.

Step 1: Marking

This is where the garbage collector identifies which pieces of memory are in use and which are not.
                     

All objects are scanned in the marking phase to make this determination. This can be a very time consuming process if all objects in a system must be scanned.

Step 2: Normal Deletion

Normal deletion removes unreferenced objects leaving referenced objects and pointers to free space.
         


The memory allocator holds references to blocks of free space where new object can be allocated.

Step 2a: Deletion with Compacting

To make new memory allocation easier and faster, we can compact (by moving referenced object together) the remaining referenced objects along with deletion of unreferenced objects.




No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...