This project has moved and is read-only. For the latest updates, please go here.

Very simple app - apparent memory leak

Mar 26, 2014 at 5:56 AM
Hi - I'm sure I'm doing something wrong here, as there is no way this kind of issue could slip through your tests...

I added clearscript to a complex application I develop, and had major memory problems, so have stripped it down to the simplest reproduction of the issue that I can.

It seems like some internal clearscript instances of c# runtime objects aren't being garbage collected.

Running .NET Memory Profiler by SciTech produces the following chart

Image

The chart is produced by the following code (just a timer on a form with a 1000ms interval)
     private void timer1_Tick(object sender, EventArgs e)
    {
        JScriptEngine aEngine = null;
        try
        {
            aEngine = new Microsoft.ClearScript.Windows.JScriptEngine();
            aEngine.AddHostType("Console", typeof(Console));
            aEngine.Execute(@"Console.WriteLine(""Hello"");");
        }
        catch (System.Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            aEngine.Dispose();
        }
    }
You can see when garbage collection happens, and half of the instances and half of the memory isn't cleaned up. The sawtooth pattern you see there will just keep going and going and going until the PC shuts down.

I am using the JScript engine as you can see, I cannot install V8 in the environment where the application will be deployed.

please help
thanks,
Simon
Coordinator
Mar 26, 2014 at 3:12 PM
Hi Simon,

Yes, we also discovered this (very recently) and posted a potential fix. The issue affects applications that repeatedly create script engine instances (of any type) and use them to run scripts that invoke host methods.

If possible, please try the fix and let us know if it works for you.

Thanks!
Apr 11, 2014 at 7:23 AM
Hi, sorry for taking so long to come back to this - I had to spend a couple of weeks on something else and didn't get back to this office. It looks like that has cured the problem. Will test further and update.

thanks very much
Simon
Coordinator
Apr 15, 2014 at 2:00 PM
Thanks for following up, Simon! Please let us know if you run into further issues.