[IronPython] Memory leak at import?
Dino Viehland
dinov at exchange.microsoft.com
Wed Nov 29 18:14:04 CET 2006
Standard modules will get compiled into static types which are not collectible by the CLR. This will result in the leak you're seeing. You can enable GenerateAsSnippets mode (-X:GenerateAsSnippets at the command line, or IronPython.Compiler.Options.GenerateModulesAsSnippets = true) and you should see the leak go away.
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Stute, Detlef ALRT/EEG4 (Fa. epos)
Sent: Wednesday, November 29, 2006 3:13 AM
To: users at lists.ironpython.com
Subject: [IronPython] Memory leak at import?
I use the IronPython.dll at my own program. The python engine is running in a worker thread (MTAThread).
I create a new engine each time and at the end I call engine.Dispose().
If I call test.py with the following content:
import sys
from time import *
import os
print 'Hello world'
If I disable the line "import os" everything is ok. But if it is enabled, each call causes in a memory leak of 4 MB.
Does anybody else have the same problem or is there a solution?
Best regards
Detlef Stute
www.seatec-gmbh.com
##########################################
CODE
##### start the thread
EngineOptions eo = new EngineOptions();
eo.ExceptionDetail = true;
eo.ShowClrExceptions = true;
engine = new PythonEngine(eo);
// create stream to get the messages from the python engine
stream = new NotifyingStream();
engine.SetStandardOutput(stream);
engine.SetStandardError(stream);
workerThread = new Thread(ExecuteScriptWorker);
// worker thread gets same culture as its caller
workerThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
workerThread.Start(parameters);
#### the thread function
[MTAThread]
private static void ExecuteScriptWorker(object parameters)
{
WorkerParameters wp = parameters as WorkerParameters;
try
{
engine.ExecuteFile(wp.scriptFile);
}
catch (ThreadAbortException ex)
{
// do something
}
finally
{
engine.Dispose();
Thread.Sleep(100);
engine = null;
workerThread = null;
GC.Collect();
}
Detlef Stute
Automotive Lighting
Reutlingen GmbH
ALRT/EEG4
Tübinger Str. 123
72762 Reutlingen
Telefon: +49 (0) 7121 35-39952 Fax: +49 (0) 7121 35-3639952
mailto:detlef.stute at al-lighting.com
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list