Google News
logo
.Net - Interview Questions
What is Garbage Collector in .Net?
Garbage collector frees the unused code objects in the memory. The memory heap is partitioned into 3 generations:
 
* Generation 0 : It holds short-lived objects.
* Generation 1 : It stores medium-lived objects.
* Generation 2 : This is for long-lived objects.

Collection of garbage refers to checking for objects in the generations of the managed heap that are no longer being used by the application. It also performs the necessary operations to reclaim their memory. The garbage collector must perform a collection in order to free some memory space.
 
During the garbage collection process :
 
* The list of live objects is recognized.
* References are updated for the compacted objects.
* The memory space occupied by dead objects is recollected. The remaining objects are moved to an older segment.

System.GC.Collect() method is used to perform garbage collection in .NET.
Advertisement