[Python-ideas] cross platform memory usage high water mark for improved gc?

Adam Olsen rhamph at gmail.com
Tue Mar 11 21:49:45 CET 2008

On Tue, Mar 11, 2008 at 12:57 PM, Christian Heimes <lists at cheimes.de> wrote:
> Aaron Watters wrote:
>  > It would be nice if the threshold would adjust based
>  > on the performance characteristics of the app.
>  > In particular it'd be nice if the garbage collector would
>  > notice when it's never finding anything and wait longer
>  > everytime it finds nothing for the next collection attempt.
>  Have you read the code and comments in Modules/gcmodule.c? The cyclic GC
>  has three generations. A gc sweep for the highest generation is started
>  every 70,000 instructions. You can tune the levels for the generations
>  yourself through the gc module set threshold function.

Not instructions.  There's a counter that's incremented on allocation
and decremented on deallocation.  Each time it hits 700 it triggers a
collection.  The collections are normally only gen0, but after 10 it
does a gen1 collection.  After 10 of the second generation it does the
gen2 (ie a full collection.)

Although, given the way the math is done, I think the 701st object
will be the one that triggers the gen0 collection, and the 12th time
that happens it does gen1 instead.  I get a grand total of.. 93233
objects to trigger a gen2 collection.  Not that it matters.

Without more detail information on what the app is doing we can't
seriously attempt to improve the heuristics for it.

Adam Olsen, aka Rhamphoryncus

More information about the Python-ideas mailing list