[IronPython] Python Memory Usage

Bernard Graham bernardgraham at gmail.com
Mon Jan 9 21:01:14 CET 2006


Thanks for the reply!

I will look into the things you proposed, but just to let you all know - my
project was referencing an older build IP and not the latest beta release.
As soon as I realized that and changed it, the memory usage completely
dropped down, event with creating a new instance of the PythonEngine.

Just for interest's sake: the reason I create a new engine is that in my
application it is possible for one script to make a call back to my c# host
application which might again invoke another python script.  If I cache the
PythonEngine, the two running scripts overrides each other's variables
(since they are all in the same scope).

I will probably have to look into object pooling, as you suggested.

Thanks again!


On 1/9/06, Andrew Pliszka <APliszka at alienforceit.com> wrote:
> 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
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060109/d0aec48a/attachment.html>

More information about the Ironpython-users mailing list