Search code examples
c#.netv8clearscript

Are V8ScriptEngine instances disposed when the parent V8Runtime is disposed?


Are V8ScriptEngine instances disposed when the parent V8Runtime is disposed?

The documentation for the library isn't clear on this. I've implemented a partial CommonJS environment, but I want to make sure the V8ScriptEngine instances created with require()s are eventually disposed.


Solution

  • I think the answer to your question is no; disposing a runtime does not automatically dispose its child engines. Each engine remains functional until it's individually disposed.

    More information here:

    The managed engine and runtime are proxies for reference-counted unmanaged objects. Disposing or finalizing a proxy decrements its target's reference count, and the target is destroyed when its reference count reaches zero. Furthermore, the unmanaged engine holds an additional reference to its parent runtime, so the runtime will be kept alive as long as the engine remains active, regardless of whether a runtime proxy exists on the managed side.