Garbage Collector Generations Algorithm

Explain the Generations Algorithm used in the context of Garbage Collector

Questions by vshylaja   answers by vshylaja

Showing Answers 1 - 6 of 6 Answers

* The (original) copying collector (Enabled by default). When this collector kicks in, all application threads are stopped, and the copying collection proceeds using one thread (which means only one CPU even if on a multi-CPU machine). This is known as a stop-the-world collection, because basically the JVM pauses everything else until the collection is completed. * The parallel copying collector (Enabled using -XX:+UseParNewGC). Like the original copying collector, this is a stop-the-world collector. However this collector parallelizes the copying collection over multiple threads, which is more efficient than the original single-thread copying collector for multi-CPU machines (though not for single-CPU machines). This algorithm potentially speeds up young generation collection by a factor equal to the number of CPUs available, when compared to the original singly-threaded copying collector. * The parallel scavenge collector (Enabled using -XX:UseParallelGC). This is like the previous parallel copying collector, but the algorithm is tuned for gigabyte heaps (over 10GB) on multi-CPU machines. This collection algorithm is designed to maximize throughput while minimizing pauses. It has an optional adaptive tuning policy which will automatically resize heap spaces. If you use this collector, you can only use the the original mark-sweep collector in the old generation (i.e. the newer old generation concurrent collector cannot work with this young generation collector).

  Was this answer useful?  Yes

Loki117

  • Dec 28th, 2008
 

Garbage collection in .Net is an automated process.

All objects are swept by the GC to check if they are still alive and are assigned a generation each sweep. The lower the generation the more frequently the objects are checked for example a gen 1 may be checked every 5ms if a object has been alive for a longer period it will be bumped up a generation (up to a max of gen 5 I believe) and checked less frequently as the logic goes that this longer living object must be a important integral object to the application if it is still being referenced. To ensure a heavy object is picked up quickly make sure to use the using key word to set it's scope and perhaps call GC.Collect() after moving out of the scope.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions