[Python-Dev] reference leaks, __del__, and annotations

Phillip J. Eby pje at telecommunity.com
Fri Mar 31 18:57:21 CEST 2006


At 11:27 PM 3/31/2006 +1000, Nick Coghlan wrote:
>Generators are even more special, in that they only require finalisation in
>the first place if they're stopped on a yield statement inside a try-finally
>block.

Or a try-except block.  Or a 'with' statement.  It's only loop blocks that 
are exempt.


>A simple Boolean attribute (e.g. __finalized__) should be enough. If the type
>has a __del__ method, then the GC would check the __finalized__ attribute. If
>it's both present and true, the GC can ignore the finaliser on that instance
>(i.e. never invokes it, and doesn't treat cycles as uncollectable because 
>of it)
>
>I don't know the GC well enough to know how hard that would be to implement,
>but I suspect we need to do it (or something like it) if PEP 342 isn't going
>to cause annoying memory leaks in real applications.

As Tim suggested, it'd be better to have the code be generator-specific, at 
least for now.  That had actually been my original plan, to make it 
generator-specific, but I was afraid of breaking encapsulation in the 
garbage collector by having it know about generators.  But now that Uncle 
Timmy has blessed the approach, I'll go back and add it in.  (On Monday, 
unless somebody gets to it before me.)



More information about the Python-Dev mailing list