]> granicus.if.org Git - python/commit
bpo-30306: release arguments of contextmanager (GH-1500)
authorMartin Teichmann <lkb.teichmann@gmail.com>
Sun, 28 Jan 2018 04:17:46 +0000 (05:17 +0100)
committerNick Coghlan <ncoghlan@gmail.com>
Sun, 28 Jan 2018 04:17:46 +0000 (14:17 +1000)
commitdd0e087edc8f1e4d2c0913236b1a62a77d9db6d8
treeada932bb080ed3a999989e2055e66df581291d4b
parentc4b1248308f051146a50ecc5e31d85d794dc8d05
bpo-30306: release arguments of contextmanager (GH-1500)

The arguments to a generator function which is declared as a
contextmanager are stored inside the context manager, and
thus are kept alive, even when it is used as a regular context
manager, and not as a function decorator (where it needs
the original arguments to recreate the generator on each
call).

This is a possible unnecessary memory leak, so this changes
contextmanager.__enter__ to release the saved arguments,
as that method being called means that particular CM instance
isn't going to need to recreate the underlying generator.

Patch by Martin Teichmann.
Lib/contextlib.py
Lib/test/test_contextlib.py