IronPython memory leak?

Run this:

for i in range(1000000000):
    a = []

It seems that the list objects created are never allocated for garbage collection. From the memory profiler, it looks like the interpreter stack frame is held on all objects in the list, so the GC can do nothing about it.

Is it for design?

EDIT:

Here is the best example of a problem. Run the following code using the memory profiler:

a = [b for b in range(1000000)]
a = [b for b in range(1000000)]
a = [b for b in range(1000000)]
a = [b for b in range(1000000)]
a = [b for b in range(1000000)]
a = [b for b in range(1000000)]
a = [b for b in range(1000000)]

You will see that the memory allocated during the list never receives garbage collection. This is because all created objects are referenced by an InterpreterFrame in the DLR.

Now run this:

def get():
    return [b for b in range(1000000)]

a = get()
a = get()
a = get()
a = get()
a = get()
a = get()
a = get()

Under the profiler, you can see that the memory here receives garbage collected properly. I assume this works because the InterpreterFrame of the function is cleared when the function exits.

, ? , , (?) IronPython script.

+3
1

"LightweightScopes" IronPython. .

var engineOptions = new Dictionary<string, object> { ["LightweightScopes"] = true };
var scriptEngine = Python.CreateEngine(engineOptions);
0

Source: https://habr.com/ru/post/1742036/


All Articles