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.

On Monday, January 18, 2021 at 8:26:13 PM UTC+5:30 d3c...@gmail.com wrote:

> On Mon, Jan 18, 2021 at 5:28 AM Vinayaka Kamath <vinayak...@couchbase.com> 
> wrote:
>
>> 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*
>>
>
>  
>    args.GetReturnValue().Set(wrapper->value.Get(Isolate));   *// return a 
> reference to the persistent object.*
>
>  
>
>>     // The intention is to force GC on wrapper->value when it goes out of 
>> scope in JS
>> }
>> ________________________________________
>> *Definition of WrapStop*
>>
>> struct 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 scope
>>        Query::Iterator *iterator;
>>         static void Callback(const v8::WeakCallbackInfo<WrapStop> &); // 
>> Callback triggered on GC
>> };
>> ________________________________________
>> *Constructor for WrapStop*
>>
>> Query::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
>>  
>> <https://groups.google.com/d/msgid/v8-users/490983ae-fd94-4b3e-aa4b-0b4ff8e0c23dn%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/c210cd53-d642-44cd-aead-a1e54f36def9n%40googlegroups.com.

Reply via email to