[Ironpython-users] LightweightScopes and scopes in general

Jeff Hardy jdhardy at gmail.com
Fri Feb 10 19:15:31 CET 2012

On Fri, Feb 10, 2012 at 10:04 AM, Igor Brejc <igor.brejc at gmail.com> wrote:
> Hi,
> I'm running embedded IronPython scripts (2.6, .NET 3.5) and I was wondering
> what happens with the stuff allocated within the script after the script has
> finished? For testing purposes I've been executing the following script
> s = set()
> for i in range(0, 1000000):
>     s.add(i)
> ...and then watching the memory usage of the application. BTW I always shut
> down the scripting engine and create a new ScriptScope for each run.
> I've noticed that in the debug mode, the memory increases after each run.
> When I do a s.clear() before finishing, the increase is unnoticeable, so I
> assume those Python sets are kept alive (even if I do GC.Collect()).

I'm taking a stab off the top of my head based on my limited knowledge
of the internals, but I do know that debug code is not collectable.
It's possible that the code itself may be holding references that keep
objects alive longer than expected.

I believe if you run the code in a separate AppDomain you can unload
the AppDomain and the code will be collected, which should take
everything else with it.

> I've also tried running in the release mode and turning on
> the options["LightweightScopes"] = true mode, which seems to help. But I
> cannot find any information about what this option actually does and what
> happens with the scope variables in general. Any info would be appreciated.

That one I'll have to leave to Dino.

- Jeff

More information about the Ironpython-users mailing list