Monday, April 19, 2010

Technical: Garbage Collector in .NET

Hi Friends,

I wanna share few terminologies related to Garbage Collector in .NET. Hope this helps u...

Garbage Collection Phases:














Types of Garbage Collection:

Garbage Collector Generations: 















 Survival & Promotions:
     Objects that are not reclaimed in a Garbage Collection are known as Survivors & are promoted to the next generation.

Variable Threshold:
     When Garbage collector detects that the survival rate is high in a generation, it increases the threshold of allocations for that generation, so that next collection gets a substantial size of reclaimed memory.

Unmanaged Resources:
      If your managed object refers unmanaged objects by native file handlers, you have to explicitly free the managed objects, because the collector tracks memory only on the managed heap.
     This can be done by using finalizers. You can make your managed object finalizable.
     When your finalizable object is detected as dead, its finalizer puts in a queue so that the cleanup actions are executed and the objects itself is promoted to next generation.

Q: How GC determines whether object is live?
A: 1. Stack Roots
     2. Garbage Collection Handles
     3. Static Data Tracking

Q: When Garbage Collection occurs?
A: 1. When system has low physical memory.
     2. When the memory that is used on managed heap surpasses acceptable threshold. [This threshold  
          continuously adjusted as the process runs.]
     3. When GC.Collect() method is called.

Thank You..!! :-)

Happy Coding..!! :-)

No comments:

Post a Comment