You can create a weak reference to the object, and when the object is GC'd in v8, the weak reference handler will get called. Check out the v8.h documentation for weak references and it will probably make sense. Mike
On Fri, May 15, 2009 at 8:38 PM, Marshall Greenblatt <[email protected] > wrote: > Hi All, > > I'm seeking a way to trigger destruction (or reference decrement) of a C++ > object attached to a V8 object when the V8 object is destroyed. For > instance, consider the following code where I create and return a new V8 > object in a function template callback: > > static v8::Handle<v8::Value> MyCallback(const v8::Arguments& args) { > // Create a new V8 object template with one internal field. > v8::Handle<v8::ObjectTemplate> my_templ = v8::ObjectTemplate::New(); > my_templ->SetInternalFieldCount(1); > > // Create a new MyClass instance. > MyClass* my_class = ...; > > // Create a new V8 object. > v8::Local<v8::Object> obj = my_templ->NewInstance(); > > // Attach the MyClass instance to the V8 object. > obj->SetInternalField(0, v8::External::New(my_class)); > > return obj; > } > > How can I clean up the MyClass instance when the associated V8 object > destroyed? Is there some way that I can assign a destructor callback for > the V8 object? > > Thanks, > Marshall > > > > --~--~---------~--~----~------------~-------~--~----~ Chromium Developers mailing list: [email protected] View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-dev -~----------~----~----~----~------~----~------~--~---
