On Tue, Jan 19, 2021 at 1:44 PM Vinayaka Kamath <vinayaka.kam...@couchbase.com> wrote: > > Is there any better way to do it? Basically I am exposing an Object Template > to JS through weak persistent handle and it holds internal resources with it. > When the object is no longer accessible in the current executing scope of the > JS code, I want to free up all the resources held by the instance of Object > Template(maybe through some callback). At first glance it seems like this is > what weak handles are meant for.
Well, now you know they're not. :-) Think of GC as "may reclaim", not "will reclaim", certainly not "will deterministically reclaim." If you need determinism, either JS needs to manually release the resource in try/finally fashion, or you neuter the object after JS is done with it, callback style: withResource(function(resource) { // do something with |resource| }); // <- withResource() neuters |resource| when the callback returns "Neuter" in this context means "free the internal resource". The object may still exist in JS land but you clear its internal pointer. -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/CAHQurc8kGF%2BfHuK8PDPrfkxzWBNevy3kZH9zn0yxHdLouVQOxw%40mail.gmail.com.