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

New Post: MemoryLeak despite disposing of V8 Script Engines

0
0
Hi infinitiesloop,

The Evaluate("[]") was being done on a NEW ScriptEngine rather than the Engine from the calling code. So the result was I was returning a js array created from one ScriptEngine back into code from another ScriptEngine.

Ah, that explains it. Although ClearScript supports exposing foreign script objects, we don't recommend it. One of the problems is that the receiving engine has no way to discover the "weight" of an external object; it only knows the size of its local proxy. That can lead to suboptimal garbage collection behavior. In this case the external object is very large (as it holds another script engine), whereas the proxy is tiny, so the engine doesn't prioritize its garbage collection.

Apparently when you do that, the object won't be cleaned up until disposing of the receiving engine.

That's correct as long as the receiving engine continues to use the proxy. If it garbage-collects the proxy, the object becomes available for managed garbage collection.

I can't reproduce the inability to explicitly clean it up by disposing of things. Perhaps there's yet more subtlety to my app preventing that.

Please let us know what you find. By the way, the next ClearScript release will use a newer V8 version that seems to have done away with the compiler thread. Here's what your test program's output will look like:
Iteration 0. Threads = 3. Memory = 23,080,960.
Iteration 1. Threads = 3. Memory = 545,955,840.
Iteration 2. Threads = 3. Memory = 1,064,095,744.
Iteration 3. Threads = 3. Memory = 1,583,087,616.
Iteration 4. Threads = 3. Memory = 2,100,662,272.
Iteration 5. Threads = 3. Memory = 2,618,945,536.
Iteration 6. Threads = 3. Memory = 3,135,750,144.
Iteration 7. Threads = 5. Memory = 3,653,799,936.
Iteration 8. Threads = 5. Memory = 4,169,682,944.
Iteration 9. Threads = 5. Memory = 4,688,252,928.
Done. Hit enter to Dispose. Threads: 5. Memory: 5,203,578,880

Done. Threads: 3. Memory: 29,364,224
Cheers!

Viewing all articles
Browse latest Browse all 2297