Hello All,I am trying to return a weak persistent handle to JS through a function template. However the v8 is crashing on triggering the codepath. What is the correct way to do it?My intention is to trigger GC on the persistent handle when it goes out of scope._____________________________________My Function Template:void QueryFunction(const v8::FunctionCallbackInfo<v8::Value> &args) {// This function is made available as Query() in the JS code.
.auto wrapper = new Query::WrapStop(isolate, iterator, it_info.iterable);args.GetReturnValue().Set(wrapper->value); // How to return this?? Set requires a pointer to Persistent
// The intention is to force GC on wrapper->value when it goes out of scope in JS}________________________________________Definition of WrapStopstruct WrapStop {explicit WrapStop(v8::Isolate *, Query::Iterator *, v8::Local<v8::Value>);virtual ~WrapStop();v8::Persistent<v8::Value> value; // Force GC on this handle when it goes out of scopeQuery::Iterator *iterator;static void Callback(const v8::WeakCallbackInfo<WrapStop> &); // Callback triggered on GC};________________________________________Constructor for WrapStopQuery::WrapStop::WrapStop(v8::Isolate *isolate, Query::Iterator *iter, v8::Local<v8::Value> val) : value(isolate, val), iterator(iter) {value.SetWeak(this, Query::WrapStop::Callback, v8::WeakCallbackType::kParameter);// Set value as weak to force GC}
--
--
v8-users mailing list
v8-u...@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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/490983ae-fd94-4b3e-aa4b-0b4ff8e0c23dn%40googlegroups.com.
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-u...@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+u...@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.