[IronPython] Memory leak at import?

Stute, Detlef ALRT/EEG4 (Fa. epos) Detlef.Stute at al-lighting.com
Wed Nov 29 12:13:29 CET 2006


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
 



More information about the Ironpython-users mailing list