JavascriptNet / Javascript.Net

.Net bindings to the V8 JavaScript engine
BSD 2-Clause "Simplified" License
828 stars 150 forks source link

Remove finalizer of JavascriptFunction #92

Closed spahnke closed 3 years ago

spahnke commented 3 years ago

The finalizer of JavascriptFunction can lead to System.AccessViolationExceptions if an object of this type is disposed manually. This PR removes it.

Resolves #90

spahnke commented 3 years ago

The finalizer only leads to problems if the JavascriptContext is disposed but JavascriptFunction objects that were created in that context are not disposed manually by calling the Dispose method (which executes ~JavascriptFunction), but collected by the garbage collector (which executes !JavascriptFunction when the original JavascriptContext is already gone). So the assumption in this PR is wrong which is why I will close it. We're currently testing several improvements regarding the memory footprint. When those are ready and sufficiently tested I will open a new PR with a proper fix for this.

In the meantime: either dispose all of your JavascriptFunction objects manually, or remove the finalizer in your fork temporarily.