Skip navigation

Garbage Collection uses an ephemeral garbage collector, which describes the lifetime of an object in generations. Using this system, the garbage collector makes the following logical assumptions:


  1. Newer objects have shorter lifetimes.


  1. Older objects have longer lifetimes.


  1. Newer objects are created around the same time and have strong relationships.


  1. Compacting a portion of the heap is faster than compacting it completely.

Let’s look at a new heap. Once the heap is created and the first set of objects are instanced, they are created and set as Generation 0.


As a new set of objects is created, Garbage Collection checks to see which objects from Generation 0 still exist, those that do exist are compacted, moved above Generation 0, and become Generation 1 As the new Generation 0 enters the same process, so does Generation 1.


Any remaining members of Generation 1 become Generation 2, and those that survived  Generation 0 become 1.


Then the new Generation 0 is created. At this point, the process continues, but there can be no higher generation  than 2; any survivors from any subsequent Generation 1 members are placed in Generation 2 with the previous Generation 1 members that survived.This also means that a complete heap compacts portions at a time, thus increasing overall speed.


Objects within Generation 0 are checked more frequently than the other two generations due to .NET’s philosophy that new objects are more likely to be the first to be removed. In other words, the longer an object is alive, the more likely is to stay alive.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.