Circular refs

David A. Cuthbert dacut at kanga.org
Tue Sep 28 00:26:03 EDT 1999


Tim Peters wrote:
> [Adrian Eyre, on immortal cyclic trash]
> > I can dream up a million ways to kludge around this bug, but I
> > was referring to a 'fix' to the Python source code. How hard can
> > it be?

> It's unclear, but I can give you a lower bound:  in all the years people
> have been whining about how easy this is to "fix", nobody has managed to fix
> it.

I've toyed with the idea of setting all of the object's data to None
(looking at __dict__ or whatever) to make sure that it doesn't hold any
references.  This seems to be clean, but remembering to run it for each
object is a real pain.  Essentially, you're writing the equivalent of a
C++-style destructor but without the benefits of such, i.e., being called
automatically for objects on the stack.

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).

In the end, I just left things as they were.  The app I was writing (medium
size, ~10kloc) just wasn't mission critical enough (and was restarted
frequently enough) to justify the effort (and running it on a Purified
version of Python verified this).




More information about the Python-list mailing list