GC time debug...

Tim Peters tim.one at comcast.net
Sat Jun 28 04:05:31 CEST 2003

[David Jeske]
> ...
> I wanted to know if it is acceptable to use Python's GC or not for
> this application. Pause times under 0.2s are non-ideal but
> acceptable. Longer than 0.2s isn't acceptable.

Python's GC is a hybrid scheme, and still uses refcounting for the vast bulk
of garbage collection in the vast bulk of applications.  A mark-sweep
variant is invoked from time to time only to reclaim unreachable cycles
(which refcounting can't touch).  The time for this is roughly proportional
to the number of live container objects plus the number of objects they
contain.  A generational scheme is also in play, so that as containers
survive collections, they're moved into older generations examined less

> If I have a cycle, I'd rather leak the memory and let it clean up with
> the apache process dies and reforks().

Then you can begin your program with:

    import gc

Refcounting will continue to reclaim non-cyclic trash.  Objects in
unreachable cycles will leak.  If you know you have some dead time, you can


to force a collection.

Of course this can't guarantee you'll never see long pauses either, since,
e.g., a long linear chain of trash objects can take an arbitrarily long time
to reclaim when the refcount on the chain's head falls to zero.

More information about the Python-list mailing list