Search code examples
memory-managementconcurrencygarbage-collectionboehm-gc

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?


Solution

  • 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: