[Python-Dev] FYI: more clues re: tee+generator leak

Phillip J. Eby pje at telecommunity.com
Mon Apr 17 18:53:57 CEST 2006


I've been fiddling a bit with test_generators this morning, and have found 
that a stripped down version of the fibonacci test only leaks if the 
generator has a reference to a *copied* tee object.  It doesn't matter 
whether the copied tee object is the second result from tee(), or if you 
just create a single tee object and use its __copy__() method, the leak 
only occurs if the cycle is:

     geniter -> frame -> ... -> copied_tee -> tdo ---+
        ^                                            |
        |                                            |
        +--------------------------------------------+

The "..." is to indicate that the frame may reference the object directly 
as a local variable, or via a cell.  I've tried it both ways and it still 
leaks.  Replacing "copied_tee" with an uncopied tee object does *not* leak.

I have no idea what this means, although I've been staring at the relevant 
itertools code for some time now.  It doesn't appear that the traverse 
functions are skipping anything.

By the way, the above cycle will leak even if the generator is never 
iterated even once; it's quite simple to set up.  I'm testing this using 
-R:: on test_generators, and hacking on the _fib function and friends.



More information about the Python-Dev mailing list