[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:

https://stackoverflow.com/help/mcve

Guessing your complaint is that:

    sys.getrefcount(itertools.repeat)

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

    weakref.ref(ns['f']), 

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>
<https://bugs.python.org/issue33814>
_______________________________________


More information about the Python-bugs-list mailing list