Garbage Collection in Dot NET

Posted By : Bipul Kumar Tiwari,

What is Garbage Collection in Dot NET:


Garbage collection is the automatic process of freeing up (or deallocating) memory which is being taken up by objects your application no longer needs.

The garbage collector basically looks at the memory (The managed heap for your application) and frees up memory which is no longer needed, that is, memory which is occupied by ‘dead objects’.

Dead Objects:

            An object is dead if it is unreachable by your code. Example is a local variable inside a method. There is no way for your code to access that variable once the method has returned, so it becomes ‘dead’.

As an application developer, you work only with virtual address space and never manipulate physical memory directly. The garbage collector allocates and frees virtual memory for you on the managed heap.

Virtual memory can be in three states:

When Garbage Collection Work?


Generations in Managed Heap:

The managed heap is organized into three generations so that it can handle short lived and long lived objects efficiently.  Garbage collection primarily occurs with the reclamation of short-lived objects that typically occupy only a small part of the heap.

Generation 0

This is the youngest generation and contains short -lived objects and Garbage collection occurs most frequently in this generation.
Example: temporary variable.

Generation 1

This generation contains the longer-lived objects that are promoted from generation 0 and serves as a buffer between short-lived objects and long-lived objects.

Generation 2

This generation contains longest -lived objects.
Example: An object at application level that contains static data

Related Articles

 

About the Author

author
Its me BIPUL who is logically minded creative at heart , a good communicator , a self taught full stack developer. I constantly focuses on my thinking , reading , collecting and creating my work in a order to enhance my skills.

I discover new dimensions for growing bussiness with a proven record in creating database and programming. I have a strong technical skills as well as strong interpersonal skills. Read more...
 

Browse By Category

Popular Articles