[Python-Dev] reference leaks, del, and annotations (original) (raw)

Thomas Wouters thomas at python.org
Fri Mar 31 15:40:47 CEST 2006


On 3/31/06, Jim Jewett <jimjjewett at gmail.com> wrote:

The checkins list has been struggling with generator reference leaks; the latest conclusion was that some are unavoidable because of del cycles.

That was Tim's conclusion, but I wasn't quite done thinking about it ;)

That sort of defeats the purpose of resource managers. (Yes, it can be worked around on a case-by-case basis.)

As I see it, part of the problem is that (1) When there is a cycle, python refuses to guess. (2) There is no way for a del method to hint at ordering constraints. (3) There is no lightweight version of del to say "I don't care about ordering constraints."

An additional (and much more complicating) problem is that del can (and is allowed to) revive 'self'. That means that halfway through your cleanup, however you decided to do it, you can suddenly find out that you shouldn't be cleaning up at all. And of course any given del can rely on all of the parts of the cycle, even if one of those parts claims it can safely break the cycle.

I think there are three different scenarios involving cycles and/or del methods:

-- 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/20060331/624508fa/attachment.html



More information about the Python-Dev mailing list