[IronPython] Python Memory Usage

Dino Viehland dinov at exchange.microsoft.com
Mon Jan 9 19:41:58 CET 2006


There's also the possibility of using the new Compile & Execute APIs to pre-compile the script once and then execute it over and over again.  Those were added in beta 1 to help improve this (I'm not sure if this will work in this specific scenario, but it's a thought).

The canonical host sample sounds like a good idea - I've gone ahead and logged a bug in our database but right now that will have to remain as a slightly lower priority.

________________________________

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Andrew Pliszka
Sent: Monday, January 09, 2006 10:18 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Python Memory Usage

Hi,

I had similar problems. I think major problem that I see with your code is that you create a new PythonEngine object every time you execute new script. I suggest caching the PythonEngine object or using object pooling. I also think the setVariable might be not releasing the object.

I also suggest you download .Net profiler and run your code under that profiler. Then you should be able to pinpoint what objects are consuming the memory. Knowing what objects are causing the leaks, try to find different way to implement them and test again.

Also take a look at last two months of the mailing list and you should find some answers on how to run scripts without leaking memory.

There are some problems with memory usage by IronPython, but developers are doing a very good job to fix those problems.

I think we also need a architectural blueprint of a stable, reliable IronPython scripting host, that people could use as a guideline. I see that more and more people would like to use IronPython as a server scripting host.

Thanks
Andrew


-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com]On Behalf Of Bernard Graham
Sent: Saturday, January 07, 2006 10:52 AM
To: users at lists.ironpython.com
Subject: [IronPython] Python Memory Usage

Hi there.

I am (like many) quite new to IronPython (and Python in general), but I am trying to use it as a scripting language for a MUD system I am creating (like the old text-based games, only multiplayer).

Now the scripts are executed and run very frequently (like when timers are executed, or when players type commands, etc).

The problem I have is that after about an hour of serving, my windows system goes out of virtual memory.  When I remove the references to IronPython and don't execute any scripts, the memory stays stable.

I am sure I am using the IronPython engine incorrectly, so I thought that maybe someone would be able to shed some light on this for me.

Here is the code I use to run a script (passed as a string to the c# method):


pythonEngine =
new PythonEngine ();
if (parameters != null)
{
  //Pass "parameters" to the script that will be executed
  foreach (PythonParameter pp in parameters)
  {
    pythonEngine.SetVariable(pp.Name, pp.Value); //Variable name/variable value
  }
}
pythonEngine.Execute(pythonScript);

This is executed everytime any script must be executed.

Please let me know if you can spot anything wrong with this...

Regards,

Bernard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060109/8e9e1f62/attachment.html>


More information about the Ironpython-users mailing list