ironpython2
ironpython2 copied to clipboard
OutOfMemory!!!How to Use CreateEngine or ScriptRuntime
for(var i = 1;i<1000;i++){
var engine = Python.CreateEngine();
var scope = engine.CreateScope();
var script = engine.CreateScriptSourceFromString(scriptTxt);
var result = script.Execute(scope);
}
the code will cause the memory to rise quickly and not reclaim; i found a lost of functionDefine instance act.

You're going to have to provide more information. When I tried it with I did not notice anything like what you're describing. What version are you using? What sort of code appears in scriptTxt?
You're going to have to provide more information. When I tried it with I did not notice anything like what you're describing. What version are you using? What sort of code appears in
scriptTxt?
netcore 3.1 lastest IronPython
when i add this line of code whichis " import os " ,the bug will review. import os .....
You're going to have to provide more information. When I tried it with I did not notice anything like what you're describing. What version are you using? What sort of code appears in
scriptTxt?when i add this line of code whichis " import os " ,the bug will review. import os .....
as the same time , urllib,urlib2,os,rpdb,random,collections ..... more
Thanks for the additional information. It looks like everything is being kept alive via IronPython.Compiler.Ast.StorageData.
The only suggestion I have would be to reuse the engine instead of creating one every time:
var engine = Python.CreateEngine();
for (var i = 1; i < 1000; i++) {
var scope = engine.CreateScope();
var script = engine.CreateScriptSourceFromString("import os");
var result = script.Execute(scope);
}
I have the same problem. Sometimes it is not possibile to reuse the engine because, as far as I know, it caches import modules and the only way to invalidate cache is to create a new engine and dispose the previous one (but this leads to huge memory usage never reclaimed).
Andrea