[Stackless] Memory leak with Stackless and generators

Richard Tew richard.m.tew at gmail.com
Sat Jan 6 21:39:36 CET 2007

On 12/21/06, Jeff Senn <senn at maya.com> wrote:
> Here, this demonstrates the leak for anyone who feels like pursuing immediately.
> Notice frames/cframe accrue and never go away.
> ---------------------------
> def foo():
>    yield 1
> import gc
> check = []
> while 1:
>    gc.collect(2)
>    before  = gc.get_objects()
>    for i in foo():
>      pass
>    gc.collect(2)
>    after = gc.get_objects()
>    print len(before),len(after)
>    for x in check:
>      if x not in after:
>         print "this never prints out so these objects are around
> forever"
>         break
>    for x in after:
>      if x is not before and x is not after and x not in before:
>        print "NEW THING",repr(x)[:40]
>        check.append(x)

Anyone want to step forward and debug this?  It is an excellent way to get
familiar with both the internals of Python and Stackless.

You could start with Jeff's reproduction case and work from there.  Or you
could diff the merged changes from the point at which this bug was
introduced and try and find something which I mismerged.  It is also possible
that there was a bug introduced in mainline Python which has already been

What I would do is merge in the latest from release25-maint and then see
if the bug still exists, and if so, then look at the earlier diffs and
try and find
a merge error.  Then fall back to debugging.

It will be several weeks before I can get around to looking into it myself.

Any help appreciated :-)

Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list