Kristján Valur Jónsson <krist...@ccpgames.com> added the comment:

tp_del() is generally invoked by tp_dealloc().  See for example 
typeobject.c:849.  gc.collect() never invokes tp_del() directy, that is left 
for the objects themselves (as part of tp_dealloc())

Now, gc already knows that if tp_del is present, it cannot cause break the 
cycle, (for various technical reasons, one of them being that tp_del would be 
invoked with various dependency objects already nerfed by tp_clear()).

But this is not always enough:
1) it may be too pessimistic.  Sometimes the tp_del method doesn't do anything 
significant, or isn't even called, depending on runtime state, so it is safe 
for gc to clear the object (see for example genobject.c:30).
2) Sometimes finalization behaviour is not defined by a tp_del method at all, 
but rather some custom code in tp_dealloc.

All this patch does, is to generalize the mechanism already provided for 
genobject.c (by PyGen_NeedsFinalizing()), to any object: Any object can signal 
to gc that: a) it is ok to collect a cycle with me in it, or b) no, it is 
unsafe to do so.  With this patch in place, PyGen_NeedsFinalizing() no longer 
needs to be a special case in gcmodule.c.

Yes, I'll send a message to python-dev.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9141>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to