R2D221 / WebView2.DOM

C# DOM bindings to be used with WebView2
MIT License
51 stars 10 forks source link

JavaScript reference can become null #4

Closed R2D221 closed 3 years ago

R2D221 commented 3 years ago

If you create a JS object (say, via document.createElement()), but don't actually attach it to the document, only keeping a C# reference, the reference can become null in the JS side since we hold it in a weak reference dictionary.

The possible solution is to instead hold the weak reference dictionary in the C# side.

R2D221 commented 3 years ago

Forgot to close this, but this has been fixed. Refer to the test in WebView2.DOM.Tests.UnitTests.ObjectPersistentInCsharpDoesntKillJsReference (there's a similar one for the opposite case, ObjectPersistentInJsDoesntKillCsharpReference)