Thank-you very much Pavel,
This particular solution resulted in a core dump, but I noticed that the
SetWeak method that takes a WeakCallbackData is deprecated. When I used the
SetWeak method that takes the WeakCallbackInfo, things work as expected.
Thanks again,
Ian
```
Stack: [0x0000000111a61000,0x0000000111b61000], sp=0x0000000111b5da08,
free space=1010k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native
code)
C [libj2v8_macosx_x86_64.dylib+0x57f2] v8::base::OS::Abort()+0x12
C [libj2v8_macosx_x86_64.dylib+0x2da7e1]
v8::internal::GlobalHandles::Node::PostGarbageCollectionProcessing(v8::internal::Isolate*)+0x1d1
C [libj2v8_macosx_x86_64.dylib+0x2dace5]
v8::internal::GlobalHandles::PostGarbageCollectionProcessing(v8::internal::GarbageCollector,
v8::GCCallbackFlags)+0x95
C [libj2v8_macosx_x86_64.dylib+0x2e81f0]
v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector,
v8::GCCallbackFlags)+0x690
C [libj2v8_macosx_x86_64.dylib+0x2e775c]
v8::internal::Heap::CollectGarbage(v8::internal::GarbageCollector, char
const*, char const*, v8::GCCallbackFlags)+0x21c
C [libj2v8_macosx_x86_64.dylib+0x2b34e1]
v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag)+0x61
```
On Tuesday, 15 March 2016 00:03:03 UTC-7, Pavel Medvedev wrote:
>
> Hi Ian,
>
> To delete user data on GC you need to create a weak persistent handle for
> your External. A user supplied callback function would be invoked on GC of
> this weak Persistent, and you can delete your data there, like this:
>
> MethodDescriptor* md = new MethodDescriptor();
>
> Local<External> ext = External::New(isolate, md);
> Persistent<External> pext(isolate, ext);
> pext.SetWeak(data, [](v8::WeakCallbackData<External, MethodDescriptor>
> const& data)
> {
> MethodDescriptor* md = data.GetParameter();
> delete md;
> });
>
> Function::New(isolate, callback, External::New(isolate, md))
>
>
> Note that GC could be called some time later (even it could)
>
> On Tuesday, March 15, 2016 at 12:15:10 AM UTC+3, Ian Bull wrote:
>>
>> I'm creating a Function with a C++ callback as follows:
>>
>> MethodDescriptor* md = new MethodDescriptor();
>>
>> md -> someFields = someValue;
>>
>> Function::New(isolate, callback, External::New(isolate, md))
>>
>>
>> In this case I associate a MethodDescriptor (md) with the function so
>> that when my callback is invoked I can get information about this
>> particular instance. How can I get notified (via a callback or destructor)
>> that this Function has been GC'd so I can clean-up the memory I allocated
>> for the MethodDescriptor?
>>
>
--
--
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.