What, Why and How Garbage Collector?

You can find lots of useful information from the msdn and other webpages…

Here are some points for understanding Garbage Collector (GC)

We can say Garbage Collector is used to free the memory (to allocate for another object) used by an object when the object is not longer used.

Considering the process of the GC, we can say:
1. When we create any object using new, the runtime will allocate memory in the next available location in the heap for that object to live.

2. It will be used by our code for sometime…..

3. The object is considered as not reachable object when the object is not referred by any other object, or the object is not referring any object object, or all the reference are set to null for that object or when the execution come out of the scope

4. The Step 1 to 3 will be continuing for the object whatever creating at runtime. So the heap will be blocked by the objects.

5. The Garbage Collector (GC) decides to recollect the memory from the object when there is not enough memory for the new object creating (as per point 1).

6. The GC will collect the objects which are not longer reachable (as per point 3). Then it will move the reachable object in to the contiguous space and reclaim the memory used by other object. So the memory will be freed from the unused/unreachable object.

The collection process is fully automatic, but there are ways we can do programming to make the GC process more efficiently.

for more information, pls refer the msdn site.

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: