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


Memory leak when re-evaluating scripts with VBScriptEngine


In version 5.4.7 and 5.4.8 there's still a memory leak related to script evaluations with the VBScriptEngine.
I've attached a test project, where 1000 predefined equations can be evaluated with VBScriptEngine or with the V8 engine. When re-evaluating the equations with V8 engine, the used process memory keeps stable, but not with the VBScriptEnginge. It seems to be an unmanaged memory leak.
To run the attached test project properly, ClearScript has to be added via nuget first.

file attachments

Closed Jan 4, 2017 at 8:46 PM by ClearScript


ClearScript wrote Jan 3, 2017 at 5:08 PM

Thanks for sharing your test project!

Using the ClearScript.V8 NuGet package (based on ClearScript 5.4.7), we can't reproduce a memory leak on Windows 10. That is, the private working set reaches a maximum beyond which it doesn't go no matter how many times we use the button to invoke the VBScript test.

What Windows version are you using? How are you detecting the memory leak?


Michael78 wrote Jan 4, 2017 at 6:43 AM

I made my tests with the VBScriptEngine and the V8 engine by using the ClearScript.V8 nuget package in version 5.4.7 under Windows 7 Pro x64.
So, I started the test application and clicked 50 times on the button "Test VB-Script", respectively the "Test V8" button and watchted the used "process memory" in the diagnostics tools in Visual Studio. I have attached two screenshots from my tests. As you can see, the used process memory when using the V8 engine keeps stable, but not for VBScript engine. In my real world application there're also evaluated hundreds of scripts hundereds of times at runtime and it would be very nice to fix this issue.

Best regards.

ClearScript wrote Jan 4, 2017 at 1:19 PM

Hi again,

We're still unable to reproduce a memory leak using your test application on Windows 7 or 10. Clicking on the "Test VB-Script" button multiple times increases memory usage at first, but it levels off after a few dozen iterations and then remains stable through several hundred additional iterations. Please see the attached screenshot from Windows 10.

We've also run a different test that uses a single VBScriptEngine instance to evaluate random x ± y expressions millions of times, with similar results. Memory usage goes up initially but levels off quickly.

Unfortunately we can't explain why our results differ from yours. VBScript is a COM component and therefore subject to registry-based redirection, but that's just a wild guess. Would it be possible for you to run the test on a different machine or clean VM to determine whether you can reproduce the leak consistently?


Michael78 wrote Jan 4, 2017 at 3:25 PM


now, I've tested my test application under a fresh installed virtual machine with Windows 7x32 and in addition with Windows 10 x64 and in both machines I get now the same result as you - no memory leak at all. I guess that the problem on my development machine is located as you already described. So this issue isn't one of ClearScript.

Nervertheless, thank you very much for your efforts!

ClearScript wrote Jan 4, 2017 at 8:47 PM

No problem at all. Thank you!