[IronPython] Memory leak in PythonEngine.Evaluate ?

Martin Maly martmaly at exchange.microsoft.com
Sat Sep 3 02:46:38 CEST 2005

Hi Szymon,

I believe I haven't yet responded to your questions. Sorry for the

> First I iterated the Embed1 sample 10 000 times. Unfortunately this
> in big increase in memory allocation (from 10K to >100K confirmed both
in Task
> Manager and with perfmon). I started looking at PythonEngine
> and it looks that although I can create its instance all calls are
> to a static global object. This doesn't "smells" nice.

This does not necessarily have to be a bad sign. The Evaluate method
ends up
parsing the expression, generating code and then executing it. There is
smart caching in place that would detect repetitive expressions and
the code. Either way, the memory is garbage collected (including the
code) so when the time comes (it depends on many variables garbage
monitors when that time comes) memory will get collected.

Pre-compiling the expression certainly helps as you have observed and I
that adding Compile method (equivalent to built-in compile function) on
PythonEngine is a good idea.

> So I wonder what happens in the PythonEngine that makes this huge
memory loss?
> Another question is, why Expr.Evaluate() is marked as "experimental"
and if it
> is safe to use it?

Good question. As part of the performance boosts, it may make sense to
expression rather than parse/generage code/execute for certain kinds of
This code is not currently used (Options.FastEval is set to false) so
from that
perspective there may be some bugs in the fast eval code path that we
have not
discovered yet.

I hope this helps

More information about the Ironpython-users mailing list