[IronPython] Memory Leak in IronPython 2.6 RC3

Dino Viehland dinov at microsoft.com
Mon Nov 30 11:26:50 PST 2009


Glad that worked, I've opened this bug to track fixing this:

http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=25478


> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Jonathan Howard
> Sent: Wednesday, November 25, 2009 9:45 AM
> To: users at lists.ironpython.com
> Subject: Re: [IronPython] Memory Leak in IronPython 2.6 RC3
> 
> That looks like it's removing that memory leak.  I'm not positive
> that's the one we're having in our production code, but it certainly
> can't hurt.
> 
> On Nov 25, 5:37 am, Dino Viehland <di... at microsoft.com> wrote:
> > My guess here (I'm on vacation so I haven't tried this) is that some
> exception info
> > is not getting cleared -
> >
> > ExceptionHelpers.DynamicStackFrames = null;
> >
> > In the catch block will probably fix it although we should probably
> > do this ourselves.
> >
> >
> >
> >
> >
> > > -----Original Message-----
> > > From: users-boun... at lists.ironpython.com [mailto:users-
> > > boun... at lists.ironpython.com] On Behalf Of Jonathan Howard
> > > Sent: Tuesday, November 24, 2009 4:45 PM
> > > To: us... at lists.ironpython.com
> > > Cc: jfelk... at drawloop.com
> > > Subject: [IronPython] Memory Leak in IronPython 2.6 RC3
> >
> > > I'm trying to track down a memory leak in our hosted IronPython
> > > application as we upgrade to 2.6 from 1.1.2.  I saw a post at
> > > stackoverflow (http://stackoverflow.com/questions/1664567/embedded-
> > > ironpython-memory-leak
> > > ) showing how to set up the environment to avoid leaking memory, but
> > > we're still having a memory leak.  If I take our identical setup code,
> > > and use it on very simple code, there's no problem, but we have
> > > thousands of lines of Python at this point.
> >
> > > Below is a minimum way to introduce a memory leak inside a hosted
> > > IronPython application.  I don't know if it's the only way, or if it's
> > > what's affecting us, but it does cause a leak:  (Obviously it needs
> > > the appropriate DLLs etc.)
> >
> > > #############################################
> >
> > > using System;
> > > using System.Threading;
> > > using IronPython.Hosting;
> > > using IronPython.Runtime;
> > > using IronPython.Compiler;
> > > using System.Collections.Generic;
> > > using Microsoft.Scripting.Hosting;
> >
> > > namespace IPyTest
> > > {
> > >     class Program
> > >     {
> > >         static void Main(string[] args)
> > >         {
> > >             bool cont = true;
> > >             while (cont)
> > >             {
> > >                 var ipy = new IPy();
> > >                 try
> > >                 {
> > >                     // Set the below boolean to "false" to run without
> > > a memory leak
> > >                     // Set it to "true" to run with a memory leak.
> > >                     ipy.run(true);
> > >                 }
> > >                 catch { }
> > >             }
> > >         }
> > >     }
> >
> > >     class IPy
> > >     {
> > >         private string scriptWithoutLeak = "import random;
> > > random.randint(1,10)";
> > >         private string scriptWithLeak = "raise Exception(), 'error'";
> >
> > >         public IPy()
> > >         {
> > >         }
> >
> > >         public void run(bool withLeak)
> > >         {
> > >             //set up script environment
> > >             Dictionary<String, Object> options = new
> > > Dictionary<string, object>();
> > >             options["LightweightScopes"] = true;
> > >             ScriptEngine engine = Python.CreateEngine(options);
> > >             PythonCompilerOptions pco = (PythonCompilerOptions)
> > > engine.GetCompilerOptions();
> > >             pco.Module &= ~ModuleOptions.Optimized;
> > >             engine.SetSearchPaths(new string[]{
> > >                 @"C:\Program Files\IronPython 2.6\Lib"
> > >             });
> > >             ScriptRuntime runtime = engine.Runtime;
> > >             ScriptScope scope = runtime.CreateScope();
> > >             var source = engine.CreateScriptSourceFromString(
> > >                 withLeak ? scriptWithLeak : scriptWithoutLeak
> > >             );
> > >             var comped = source.Compile();
> > >             comped.Execute(scope);
> > >             runtime.Shutdown();
> > >         }
> > >     }
> > > }
> > > _______________________________________________
> > > Users mailing list
> > > Us... at lists.ironpython.com
> > >http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> > _______________________________________________
> > Users mailing list
> > Us... at lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-
> ironpython.com
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Users mailing list