Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Issue: Continuous Allocation of V8ScriptEngine Can Crash Application [106]

$
0
0
When allocating a V8ScriptEngine objects within a loop causes memory to remain allocated even if you force all references to the object to null and eventually crashes the application with a System.AccessViolationException. The details of the crash is below.

_Currently coding against version 5.4.5.0 of ClearScript._

__This Code Snippet Fails (Normally at iteration 134 the failure occurs)__
for (int i = 1; i <= 1000; i++)
{
var v8Engine = new Microsoft.ClearScript.V8ScriptEngine();
v8Engine = null;
}

__This Code Snippet Works:__
for (int i = 1; i <= 1000; i++)
{
var v8Engine = new Microsoft.ClearScript.V8ScriptEngine();
v8Engine = null;
//Invoking Garbage Collection Every 50 V8ScriptEngine object allocated
//Fixes the issue
if(i%50 == 0)
GC.Collect();
}

__Here are the details of the crash:__
Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: ClearScriptDemo.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 572a5c94
Problem Signature 04: ClearScriptV8-32
Problem Signature 05: 5.4.5.0
Problem Signature 06: 56e184c1
Problem Signature 07: e6
Problem Signature 08: 78
Problem Signature 09: System.AccessViolationException
OS Version: 6.1.7601.2.1.0.256.4
Locale ID: 1033
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

Comments: Thank you again for your quick response. Your explanation is very clear in terms of the managed memory. I tried the CollectGarbage routine and that unfortunately did not work. I have a question? Does the V8Runtime object store a reference to the V8ScriptEngine object it creates. If so, that may explain why the garbage collector does not clean up the managed memory. Although the V8ScriptEngine has been marked for disposal, if the V8Runtime is still referencing the object, wouldn't the garbage collector overlook cleaning up the memory until the V8Runtime object's reference count is 0? We plan to use ClearScript in a high performance application and we want to minimize the overhead of initializing script engines. Our model may require several hundreds of script engines to be initialized at startup. I think we can leverage allocating a few V8Runtime objects (i.e one per core) and then allocate a large set of V8ScriptEngine objects per runtime. Another quick question. How many script engines per runtime do you suggest, and will this allocation strategy be multi-thread safe? Again thank you so much for the feedback. We are really impressed with the power of the ClearScript library and the ease to which we can integrate scripting into our code base. ERIC

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>