[IronPython] Python Memory Usage

Andrew Pliszka APliszka at AlienForceIT.Com
Mon Jan 9 19:17:43 CET 2006


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/d69ce13d/attachment.html>


More information about the Ironpython-users mailing list