[Python-Dev] Cycle collection enhancement idea

Antoine Pitrou solipsis at pitrou.net
Sun Jun 29 16:40:54 CEST 2008


eyal.lotem+pyutils <at> gmail.com <eyal.lotem <at> gmail.com> writes:
> 
> Additionally, there is another problem: If the cycle is not
> temporarily revived, and you call __del__ manually, it may break the
> cycle by removing the references.
> Thus, objects in the cycle will go down to refcount=0 during your
> attempt to call __del__'s on the objects in the cycle.

But if we use gcmodule's current linked list mechanisme, wouldn't this situation
 be correctly handled by _PyObject_GC_UNTRACK? That is, before the object is
destroyed, the gc module already automatically removes it from its current
"collection". Therefore, walking the collection (in this case, the list of
unreachable objects) still does the right thing.
(ISTM the gc relies heavily on this property)

> Then, you might want to disable the
> normal __del__ calling that occurs as part of the later destruction of
> the cycle.

I was thinking a flag in the PyObject header would do the trick but there aren't
any flags in the PyObject header... *gasp*.






More information about the Python-Dev mailing list