[Python-ideas] Why not break cycles with one __del__?

Nick Coghlan ncoghlan at gmail.com
Tue Sep 14 11:51:19 CEST 2010

On Tue, Sep 14, 2010 at 12:44 PM, Greg Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> Nick Coghlan wrote:
>> Alternatively, when building finalizers, build two
>> lists: one for objects with __del__ methods and one for objects that
>> are reachable from objects with __del__ methods.
> But since it's a cycle, isn't *everything* in the cycle
> going to be reachable from everything else?

In addition to what Tim said, there may be more than one cycle being
collected. So you can have situations like objects, A, B C in one
cycle and D, E, F in a different cycle. Suppose A, B and D all have
__del__ methods. Then your two lists would be:

__del__ method: A, B, D
Reachable from objects with __del__ method: A, B, C, E, F

It's just another way of viewing what the OP described: cycles
containing only a single object with __del__ don't actually have an
ordering problem, so you can just call it before you destroy any of
the objects.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list