[Question] Is there a way to reference the object in the callback?
Yaojian opened this issue · 2 comments
Yaojian commented
I tried to execute a function which belongs to the weak referenced object inside the callback, for example, obj.dispose()
. Is it possible?
The callback passed in weak(Object obj [, Function callback])
does not receive any argument when it is invoked, while referencing the obj
inside the callback directly will prevent the callback being invoked as the obj
still has active reference and cannot be GCed.
acarstoiu commented
Yes, there is, see the README.md
file. What you're looking for is the weak.get(ref)
function.
mvduin commented
Calling weak.get(ref)
inside the callback results in a segfault.