On Tue, Jan 19, 2021 at 4:44 AM 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. > > https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_module.cc#L886-L890 (using setweak) https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_module.cc#L836 (the release callback) don't need persistent... which are things that shouldn't be garbage collected... Node's ObjectWrap class is a generic thing used to wrap C++ classes in JS objects which get garbage collected and have their destructor called... http://thlorenz.com/node-dox//build/node-v8.x/html/d4/d14/node__object__wrap_8h_source.html > 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 > <https://groups.google.com/d/msgid/v8-users/9dcf1983-b2c2-4882-8bcc-8140fdc11e90n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- -- 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/CAA2GJqWPikE_sTvsL%3DWnXO3R_Pv%3DLbGy91%3Dt-dV_V%3DmQm7i8tA%40mail.gmail.com.