#934 – How Generations Help the Garbage Collector Run More Efficiently

Objects allocated on the managed heap are grouped into generations by the garbage collector:

  • Generation 0 – Newest objects
  • Generation 1 – Objects that have survived one GC pass
  • Generation 2 – Objects that have survived more than one GC pass

When the garbage collector performs a GC pass, it looks only at objects in generation 0, releasing memory for any that are no longer reachable.  In this way, the garbage collector is more efficient, because it is only looking at a portion of the managed heap.

If the garbage collector has collected Gen 0, but the application requires more memory, the garbage collector can then garbage collect generation 1.  If the application still requires memory after collecting generation 1, it can move on to generation 2.

This scheme relies on the fact that if an object survives one GC pass, it likely has a longer lifetime and will survive future passes.

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

2 Responses to #934 – How Generations Help the Garbage Collector Run More Efficiently

  1. Pingback: Dew Drop – September 19, 2013 (#1,627) | Morning Dew

  2. Pingback: #936 – Visualizing Garbage Collection Generations | 2,000 Things You Should Know About C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: