[Patches] Garbage collection patches for Python

nascheme@enme.ucalgary.ca nascheme@enme.ucalgary.ca
Sun, 13 Feb 2000 04:09:08 -0700


On Sun, Feb 13, 2000 at 11:38:12AM +0100, Fredrik Lundh wrote:
> is this scheme perhaps documented somewhere?

Here is my (hopefully accurate) explanation:

First, we keep track of objects that can be involved in reference
cycles.  To collect reference cycles, we find all the objects
reachable from these tracked objects.  For each object in this
"reachable set", we determine if the object is referred to by an
object not in the set (the reference counts tell us this).  If an
object is referred to from outside the set, it and all objects
reachable from it are removed from the set.  Once we finish doing
this for each object, we know that the objects remaining in the
set are unreachable and can be collected.

This scheme will find all reference cycles that contain a least
one of the tracked objects and are composed of objects that the
implementation knows how to "follow".  The current implementation
only tracks dictionaries and knows how to follow lists, tuples,
dictionaries, classes and instances.

There is a bit more explaination in the comments in the
implementation.  You can find it here:

    http://www.acs.ucalgary.ca/~nascheme/python/gc-cycle.diff

I have recently updated patch to include doc strings so you might
want to reload it if you already have it.


    Neil