Garbage Collection

Recently I had a chance to revisit the .Net framework concept ‘Garbage Collection’. It was quite interesting.
Garbage collection basically to reclaim the memory of th eobject which no longer being used.CLR(common language runtime) using the garbage collection algorithm to identify if the application is using an object or not?

How the algorithm works?
All the application has the roots( ie: static, global variable, CPU registers) the roots refer to an objects on the managed heap . The list of active roots is maintained by the just-in-time (JIT) compiler and common language runtime. Initially garbage collection assume that all the objects in the heap are garbage. Finally it assume and reclaim the memory of the obejct which doesnot have the pointer with the root.

Object In Heap

Object In Heap

 

Heap after garbage collection

Advertisements

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: