[Python-Dev] reference leaks, del, and annotations (original) (raw)
Thomas Wouters thomas at python.org
Sat Apr 1 12:19:34 CEST 2006
- Previous message: [Python-Dev] reference leaks, __del__, and annotations
- Next message: [Python-Dev] reference leaks, __del__, and annotations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 4/1/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
I'm becoming more and more convinced that we desperately need something better than del methods to do finalisation. A garbage collector that can't be relied upon to collect garbage is simply not acceptable.
Sure. I don't believe it's too hard, it just means violating some of the premises people have been writing del methods under. For instance, to clean up cycles nicely we might have to set some attributes to None before calling del, so you can't rely on attributes being meaningful anymore. However, this is already the case for global names; I've seen many people wonder about their del method raising warnings (since exceptions are ignored) going, say, 'NoneType has no attribute 'registry'' when they try to un-register their class but the global registry has been cleaned up already. While we're at it, I would like for the new del (which would probably have to be a new method) to disallow reviving self, just because it makes it unnecessarily complicated and it's rarely needed. Allowing a partially deleted object (or an object part of a partially deleted reference-cycle) to revive itself is not terribly useful, and there's no way to restore the rest of the cycle. I suggested a dealloc method earlier in the thread to do this. I didn't think of allowing attributes to be cleared before calling the method, but I do believe that is necessary to allow, now that I've thought more about it.
An alternative would be to make GC check for a 'cleanup-cycle' method on any of the objects in the cycle, and just feed it the complete cycle of objects, asking it to clean it up itself (or maybe reconnect one of the objects itself.) That would also make debugging uncollectable cycles a lot easier ;-) But I'm not sure whether that will improve things. The generator example, the trigger for this discussion, could solve its cycle by just closing itself, after which the cycle is either broken or reconnected, but I don't know if other typical cycles could be resolved that easily.
-- Thomas Wouters <thomas at python.org>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-dev/attachments/20060401/e0aa5a9a/attachment.htm
- Previous message: [Python-Dev] reference leaks, __del__, and annotations
- Next message: [Python-Dev] reference leaks, __del__, and annotations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]