Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between generational and incremental garbage collection?

I think that both (generational and incremental) are different approaches to make the garbage collection pauses faster. But what are the differences between generational and incremental? How do they work? And which one is better for real time software / produces less long pauses?

Also, the Boehm GC is any of those?

like image 921
Damian Avatar asked Feb 23 '11 14:02

Damian


People also ask

What is generation garbage collection?

Collecting a generation means collecting objects in that generation and all its younger generations. A generation 2 garbage collection is also known as a full garbage collection, because it reclaims objects in all generations (that is, all objects in the managed heap).

What are different garbage collection methods?

There are two ways to do it : Using System. gc() method: System class contain static method gc() for requesting JVM to run Garbage Collector. Using Runtime.

What are generations and how are they used by the garbage collector?

A generational garbage collector collects the short-lived objects more frequently than the longer lived ones. Short-lived objects are stored in the first generation, generation 0. The longer-lived objects are pushed into the higher generations, 1 or 2.

What are the disadvantages of generational garbage collection?

Generational Garbage Collection. One of the limitations of simple garbage collection algorithms is that the system has to analyze all the data in heap. For example, a Copying Algorithm has to copy all the live data every time it used. This may cause significant increases in execution time.


2 Answers

A generational GC is always incremental, because it does not collect all unreachable objects during a cycle. Conversely, an incremental GC does not necessarily employ a generation scheme to decide which unreachable objects to collect or not.

A generational GC divides the unreachable objects into different sets, roughly according to their last use - their age, so to speak. The basic theory is that objects that are most recently created, would become unreachable quickly. So the set with 'young' objects is collected in an early stage.

An incremental GC may be implemented with above generational scheme, but different methods can be employed to decide which group of objects should be sweeped.

One might look at this wikipedia page and further downward, for more information on both GC methods.

According to Boehm's website, his GC is incremental and generational:

The collector uses a mark-sweep algorithm. It provides incremental and generational collection under operating systems which provide the right kind of virtual memory support.

As far as a real time environment is concerned, there are several academic research papers describing new and ingenious ways to do garbage collection:

  • Nonblocking Real-Time Garbage Collection
  • Real-time garbage collection by IBM has good explanation on differences.
like image 168
Andrew Avatar answered Oct 19 '22 01:10

Andrew


An incremental garbage collector is any garbage-collector that can run incrementally (meaning that it can do a little work, then some more work, then some more work), instead of having to run the whole collection without interruption. This stands in contrast to old stop-the-world garbage collectors that did e.g. a mark&sweep without any other code being able to work on the objects. But to be clear: Whether an incremental garbage collector actually runs in parallel to other code executing on the same objects is not important as long as it is interruptable (for which it has to e.g. distinguish between dirty and clean objects).

A generational garbage collector differentiates between old, medium and new objects. It can then do copying GC on the new objects (keyword "Eden"), mark&sweep for the old objects and different possibilities (depending on implementation) on the medium objects. Depending on implementation the way the generations of objects are distinguished is either by region occupied in memory or by flags. The challenge of generational GC is to keep lists of objects that refer from one generation to the other up to date.

Boem is an incremental generational GC as cited here: http://en.wikipedia.org/wiki/Boehm_garbage_collector

like image 35
Bernd Elkemann Avatar answered Oct 19 '22 02:10

Bernd Elkemann