-
Notifications
You must be signed in to change notification settings - Fork 307
Description
Description
There is a memory leak when calling the list function with an OrderedDict. Even after the runtime has been shut down, objects of type PythonGetMemberBinder, PythonType, FunctionDefinition, FunctionCode etc. remain referenced and will not be garbage collected.
Steps to Reproduce
(Repro project available here: https://github.com/spkl/IronPythonMemoryRepro)
- In a .NET 6 program, create a ScriptEngine and ScriptScope.
- Create a ScriptSource from a file containing the following code:
import collections
def MyMethod(dummy):
od = collections.OrderedDict()
for i in range(100):
od[i] = []
for v in list(od.values()):
continue
return dummy- Execute the ScriptSource.
- Call the
MyMethodfunction. - Shut down the engine.
- Repeat this 50 times.
Expected behavior: The memory footprint is stable. (For reference: After the first execution, it is ~50MB).
Actual behavior: The memory footprint exceeds 300 MB after 50 repetitions. Forcing a garbage collection does not change it significantly. (With a larger, more complex example, we have observed ~600 MB of additional, uncollectable memory after 30 script executions.)
Workaround: Instead of for v in list(od.values()):, use for v in [x for x in od.values()] or for v in od.values():.
Versions
The issue is reproducible with both 3.4.0 and 3.4.1.