Closed MaxDesiatov closed 3 years ago
Maybe we could stash the event callbacks in a global registry? That’s a simpler case than storing arbitrary functions since we know to remove them from the registry when calling removeEventListener
(or watching for the node to be removed from the DOM?) Perhaps we can be OK with some level of memory leakage by default to provide good UX, as long as we document it.
What if removeEventListener
was never called? The only thing we can rely on is a call of deinit
on a corresponding element, which is what we're doing right now. JavaScript won't let us know when exactly that element is gone.
I'm still convinced that the whole closure deallocation problem can be resolved with Wasm reference types as I described in https://github.com/swiftwasm/JavaScriptKit/issues/106. At least reference types are already being worked on in Safari, while I'm not sure if they'll even consider implementing FinalizationRegistry
.
The current test was meaningless as we didn't assert on the text content of
queriedButton
.I've also removed
addEventListener
because it doesn't actually work. Thebutton
instance is already deallocated by the time that test has finished, so the closure passed toaddEventListener
is released too. We need to find a way to run async tests like this, and I have a few thoughts, but this still needs to be explored.