What are the different generaions of Garbage Collection and
how do they work
Answer Posted / komilla shaheen
One feature of the garbage collector that exists purely to
improve performance is called generations. A generational
garbage collector takes into account two facts that have
been empirically observed in most programs in a variety of
languages:
1. Newly created objects tend to have short lives.
2. The older an object is, the longer it will survive.
Generational collectors group objects by age and collect
younger objects more often than older objects. When
initialized, the managed heap contains no objects. All new
objects added to the heap can be said to be in generation
0, until the heap gets filled up which invokes garbage
collection. As most objects are short-lived, only a small
percentage of young objects are likely to survive their
first collection. Once an object survives the first garbage
collection, it gets promoted to generation 1.Newer objects
after GC can then be said to be in generation 0.The garbage
collector gets invoked next only when the sub-heap of
generation 0 gets filled up. All objects in generation 1
that survive get compacted and promoted to generation 2.
All survivors in generation 0 also get compacted and
promoted to generation 1. Generation 0 then contains no
objects, but all newer objects after GC go into generation
0.
Thus, as objects "mature" (survive multiple garbage
collections) in their current generation, they are moved to
the next older generation. Generation 2 is the maximum
generation supported by the runtime's garbage collector.
When future collections occur, any surviving objects
currently in generation 2 simply stay in generation 2.
Thus, dividing the heap into generations of objects and
collecting and compacting younger generation objects
improves the efficiency of the basic underlying garbage
collection algorithm by reclaiming a significant amount of
space from the heap and also being faster than if the
collector had examined the objects in all generations.
A garbage collector that can perform generational
collections, each of which is guaranteed (or at least very
likely) to require less than a certain maximum amount of
time, can help make runtime suitable for real-time
environment and also prevent pauses that are noticeable to
the user.
Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
What is parallel foreach c#?
What are boxing and unboxing?
What is a statement c#?
Is it possible to inline assembly or il in c# code?
What is difference between asp net and c# net?
Can we set image Source dynamically using C# in WPF application?
How can we sort an array in c#?
What are access modifiers in c#?
Define multicast c# delegate?
What is an assembly qualified name
What are the collections in c#?
What do u mean by delegation of authority?
What do you mean by generic class in c#?
What is multicast delegate explain with example?
What namespace is list in c#?