Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is meant by Generations of Garbage Collector?

Tags:

c#

.net

What is meant by Generations of Garbage Collector in C#? Is it different from the concept or is GENERATION only a term used to represent the time period?

like image 297
Rahul Tripathi Avatar asked Sep 12 '12 17:09

Rahul Tripathi


People also ask

What is generation in garbage collector C#?

C# garbage collection belongs to the tracing variety. It's often called a generational approach since it employs the concept of generations to figure out which objects are eligible for collection. Memory is divided into spaces called generations. The collector starts claiming objects in the youngest generation.

What is Gen0 Gen1 Gen2?

Gen0, Gen1 & Gen2 are the generations in . net GC. New objects created in Gen0. objects survived on Garbage Collection will be moved to the next generation. GC will be triggered when there is no space in each generations.

How many generations does .NET GC?

Generations. The . NET Garbage Collector has 3 generations and each generation has its own heap that that is used for the storage of allocated objects.

How many types of garbage collectors are there?

There are four types of the garbage collector in Java that can be used according to the requirement: Serial Garbage Collector. Parallel Garbage Collector. Concurrent Mark Sweep (CMS) Garbage Collector.


1 Answers

A GC generation relates to how many garbage collections an object survives.

All objects start in generation 0. When a garbage collection occurs, and a generation N object cannot be collected, it is moved to generation N+1.

The generations are used to performance optimize garbage collection. It is generally true that generation 0:

  1. Is a small fraction of the entire heap in size
  2. Has a lot of short-lived objects.

Therefore, when garbage collection occurs, the garbage collector starts by collecting generation 0, which will be quick. If enough memory could be released, no need to look at the older generations, and therefore, collection can happen quickly.

Books could be written about the subject; but to start with, there is some great details in this article, or the reference here.

like image 169
driis Avatar answered Oct 13 '22 08:10

driis