[racket] Yet another garbage collection question: major GC cycles

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Feb 15 17:03:26 EST 2013

At Fri, 15 Feb 2013 16:55:09 -0500 (EST), Galler wrote:
> Matthew,
> 
> >>>>> A major collection is triggered when current memory use is twice 
> >>>>> the use at the last major collection.
> 
> I'm not following this sentence, as it implies logarithmic growth in 
> memory, which is not observed.

The comparison is memory use *before* a prospective GC to memory use
*after* the preceding GC.

Suppose that 100MB of data was live at the end of a major GC. When the
total memory use goes past 200MB, then a major GC will be triggered.
After the GC, then maybe only 100MB of data is live --- in which case
overall heap size is staying about constant, and the next major GC will
happen when memory use gets back up to 200MB.

If memory use is 200MB and a GC reclaims only 50MB, then 150B is left,
and the next major GC will be at 300MB of memory use, in which case the
heap size is growing. If memory use is 200MB and 120MB is reclaimed,
then memory use is 80MB, and the heap size is shrinking.

There's a lot of play in the actual numbers --- for example, a GC is
normally triggered when the nursery is full, which is probably at some
that pushes total memory use beyond the specific threshold for a major
GC --- but that's the basic idea.


Posted on the users mailing list.