1.) How Garbage collector (GC) works in .NET ?
In .NET,this class method influence when an object is garbage collected and when resources allocated by an object are released. Properties in this class provide information about the total amount of memory available in the system and the generation, or age category, of memory allocated to an object. Periodically, the garbage collector performs garbage collection to reclaim memory allocated to objects for which there are no valid references. Garbage collection happens automatically when a request for memory cannot be satisfied using available free memory. An application can force garbage collection using the Collect method.
There are following steps in Garbage collection as given below.
In .NET,this class method influence when an object is garbage collected and when resources allocated by an object are released. Properties in this class provide information about the total amount of memory available in the system and the generation, or age category, of memory allocated to an object. Periodically, the garbage collector performs garbage collection to reclaim memory allocated to objects for which there are no valid references. Garbage collection happens automatically when a request for memory cannot be satisfied using available free memory. An application can force garbage collection using the Collect method.
There are following steps in Garbage collection as given below.
- The garbage collector searches for managed objects that are referenced in managed code.
- The garbage collector attempts to finalize objects that are not referenced.
- The garbage collector frees objects that are not referenced and reclaims their memory.