#933 – The Garbage Collector Groups Objects into Generations

Referenced-typed objects in an application have different lifetimes.  The application will use some objects as long as the application is running.  Others are referenced only during execution of a single method.

If the garbage collector always examined every object whenever it did a garbage collection pass, it would spend a lot of time reexamining longer-living objects that can’t yet be garbage collected.  The garbage collector can perform more efficiently by looking at only a subset of all objects during each pass.  It does this by grouping objects into generations:

  • Generation 0 – Objects that have been created since the last GC pass  (newest objects)
  • Generation 1 – Objects that have survived one pass of the GC
  • Generation 2 – All other objects  (oldest objects)

The garbage collector examines and collect objects in generation 0, moving to higher generations only if it needs additional memory.

Objects are promoted to the next generation only if a GC pass is done on the generation in which they are located.

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.

7 Responses to #933 – The Garbage Collector Groups Objects into Generations

  1. Pingback: #934 – How Generations Help the Garbage Collector Run More Efficiently | 2,000 Things You Should Know About C#

  2. Pingback: #935 – Large Objects Are Allocated on the Large Object Heap | 2,000 Things You Should Know About C#

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

  4. Pingback: #937 – Forcing a Garbage Collection | 2,000 Things You Should Know About C#

  5. Pingback: #938 – Finding Out What GC Generation an Object Is In | 2,000 Things You Should Know About C#

  6. Pingback: #939 – Not All Objects on Heap Are Promoted to Next GC Generation | 2,000 Things You Should Know About C#

  7. Sofia Khatoon says:

    Reblogged this on Guidelines for web development and commented:
    As most objects are created within a method and they go out of scope when the method finishes .. generation zero objects are collected most frequently ..

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: