#12 Root-GC

Garbage Collector(GC) has to remove the object that are no longer referenced in program.It has to clean up the heap memory so that it can free up space for objects which are newly created.


Every object’s start/base address in heap is referenced to GC by an element called Root.So Root is nothing but an address where the object is located in Heap.

Usage of Root:

1.Whenever GC starts cleaning the Heap,it starts by assigning the default value of 0 to Sync index (Every object has type object pointer and sync index along with its fields).

2.It then compares the Root(Contains all address of object that are in Heap) with all objects in Heap.Whenever there is a match with Root and Object in Heap,it marks the Sync index to 1.

3.GC has then checks for objects which has sync index to 0.These objects are no longer of use and are removed from Heap.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s