views:

332

answers:

3

I'm hosting IronPython in a c#-based WebService to be able to provide custom extension scripts. However, I'm finding that memory usage sharply increases when I do simple load testing by executing the webservice repeatedly in a loop.

IronPython-1.1 implemented IDisposable on its objects so that you can dispose of them when they are done. The new IronPython-2 engine based on the DLR has no such concept.

From what I understood, everytime you execute a script in the ScriptEngine a new assembly is injected in the appdomain and can't be unloaded.

Is there any way around this?

+1  A: 

You could try creating a new AppDomain every time you run one of your IronPython scripts. Although assebmlies cannot be unloaded from memory you can unload an AppDomain and this will allow you to get the injected assembly out of memory.

Sean
+1  A: 

You need to disable the optimized code generation:

var runtime = Python.CreateRuntime(); var engine = runtime.GetEngine("py"); PythonCompilerOptions pco = (PythonCompilerOptions)engine.GetCompilerOptions(); pco.Module &= ~ModuleOptions.Optimized;

// this shouldn't leak now while(true) { var code = engine.CreateScriptSourceFromString("1.0+2.0").Compile(pco); code.Execute(); }

A: 

Turns out, after aspnet_wp goes to about 500mb, the garbage collector kicks in and cleans out the mess. The memory usage then drops to about 20mb and steadily starts increasing again during load testing. So there's no memory 'leak' as such.

HS
You migth interested in the issue I submit to IP team last year.http://www.mail-archive.com/[email protected]/msg05771.html
Sake