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.
On Tuesday, January 19, 2021 at 6:05:16 PM UTC+5:30 Ben Noordhuis wrote: > On Tue, Jan 19, 2021 at 12:26 PM Vinayaka Kamath > <vinayak...@couchbase.com> wrote: > > > > It seems like the v8 is crashing when I follow this. To add more to what > I am trying to do, when the "value" goes out of scope I want it to get > garbage collected and in the callback, I am freeing up resources held by > the value. I am basically forcing GC using isolate->LowMemoryNotification() > only when I am creating a new item that holds the same type of resource as > of that of "value". I've ensured that I'm calling LowMemoryNotification() > in the same thread as that of persistent->setWeak(). However one of the > threads running the process is crashing. > > Not a direct answer to your question but it sounds like you're > approaching this wrong. The garbage collector is not a good mechanism > for deterministic resource management. > > I also get the impression that you have the wrong idea what "weak" > means here: it's not weak in the sense that it's immediately eligible > for collection, only when there are no strong references (and only > when the garbage collector feels like it - V8's GC is very lazy.) > > If your JS code is the functional equivalent of `globalThis.value = > create()`, then you can call LowMemoryNotification() all you want but > it's never going to get collected. > -- -- 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/9dcf1983-b2c2-4882-8bcc-8140fdc11e90n%40googlegroups.com.