[pypy-issue] Issue #2833: Memory leak with non-exhausted nested generators (pypy/pypy)

František Skála issues-reply at bitbucket.org
Tue May 22 09:12:42 EDT 2018

New issue 2833: Memory leak with non-exhausted nested generators

František Skála:

When I have nested generators and don't exhaust them fully, memory is not released properly. I've tried a version with and without closing the generators manually, but I did not observe any difference.

Tested in an ubuntu 16.04 docker image with just pypy3 installed:

$ pypy3 --version
Python 3.5.3 (fdd60ed87e94, Apr 24 2018, 06:10:04)
[PyPy 6.0.0 with GCC 6.2.0 20160901]

$ uname -a
Linux 60286eff83ae 4.4.0-124-generic #148-Ubuntu SMP Wed May 2 13:00:18 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

The code showing this problem (main.py) while closing the generators manually:

def sample_generator():
    yield 3

def nesting_generator():
    inner_generator = sample_generator()
        for x in inner_generator:
            yield x

def leak():
    outer_generator = nesting_generator()

while True:

Command used: `pypy3 main.py`

Expected behaviour:

* memory consumption of the pypy3 process doesn't grow over time

Actual behaviour:

* memory consumption growing rapidly (~250MB increase each second)

More information about the pypy-issue mailing list