[docs] [issue33814] exec() maybe has a memory leak

Tim Peters report at bugs.python.org
Sat Jun 9 20:46:08 EDT 2018

Tim Peters <tim at python.org> added the comment:

Dan, your bug report is pretty much incoherent ;-)  This standard Stack Overflow advice applies here too:


Guessing your complaint is that:


keeps increasing by 1 across calls to `leaks()`, then as Eric said it will drop back to its original value after a `gc.collect()` call.

Steven, best I can tell weakrefs have nothing to do with this.  The refcount on itertools.repeat increases if


is deleted.

It's a simple reference cycle.  That is

    ns['f'].__globals__ is ns

is True, so `ns` can't be collected via reference counting, and so `ns` also holds a reference to the irrelevantly renamed `itertools.repeat` too until cyclic gc can detect the trash cycle.

Dan, if that's _not_ what you're complaining about, please follow the advice at the top and add a focused, minimal example of what you are talking about.  In the meantime, I'm closing this as not-a-bug.

nosy: +tim.peters
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

Python tracker <report at bugs.python.org>

More information about the docs mailing list