Circular refs

Tim Peters tim_one at email.msn.com
Tue Sep 28 01:52:36 EDT 1999


[David A. Cuthbert]
> ...
> I've also toyed with the idea of replacing the Python gc code with
> a Lins collector (which is based on reference counting but has the
> ability to reclaim cycles).

You would hit bad problems with this (I did <0.5 wink>).  Such as: (a) you
can't color reclaimed cells (Python doesn't pretend to own memory, and
happily accepts PyObject* pointers from external modules -- the type's
destructor decides what to do with reclaimed cells, and Python never assumes
it can carry info in a dead external object); (b) even adding two bits for a
color field actually adds 4 bytes to each object, due to structure alignment
rules on popular platforms; and, (c) the Lins "local" sweep too often ends
up touching the whole world, since e.g. from any frame you can reach its
function's module's global namespace, from which you can often reach sys,
from whose sys.modules dict the entire system is reachable.

At a more basic level, there's no protocol now for an external type to
participate in pointer-chasing, so an object of an extension type is a black
hole in the graph -- for safety's sake, you have to assume it sucks in
everything as reachable.  The groundwork just isn't there for any exact
traversing scheme (be it Lins' or traditional mark&sweep).

> In the end, I just left things as they were.

By an amazing coincidence, so has Guido <wink>.

garbage-is-in-the-eye-of-the-reclaimer-ly y'rs  - tim






More information about the Python-list mailing list