-
Notifications
You must be signed in to change notification settings - Fork 563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory leak with callback closures in napi #3706
Labels
Comments
tronical
added
bug
Something isn't working
a:language-javascript
JavaScript bindings (mF,bS)
labels
Oct 19, 2023
The theory was wrong in the sense that the GC doesn't collect
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following test case should print "deleted" to indicate that we're not leaking memory.
Run inside
api/napi
, alongside atest.slint
:Run with
node --expose-gc ./test.js
If you comment out the code in the closure, you'll see that
app
gets garbage collected.Our theory is that the reference to the JS closure kept in the Rust implementation is seen as a root by the garbage collector. One approach we discussed as a remedy would be to store all the callback closures inside the JS object (as properties in an array perhaps), instead of using a strong
napi::Ref
that becomes a root.The text was updated successfully, but these errors were encountered: