It still doesn't seem to work for me, here's the exact code I use: v8::Handle< v8::Object > handle( v8::Object::Cast( *value ) ); v8::Persistent< v8::Object >( handle ).ClearWeak();
"value" is a "const v8::Handle< v8::Value >&" that I get from a "const v8::Arguments&" to a function. The value is previously created as a Persistent from another function. Using the code from above, the callback for the weak reference is still being run on GC. 2009/12/1 Søren Gjesse <[email protected]> > Sorry for the confusion I you should use the Persistent constructor to cast > a Handle to Persistent when the Handle refers to a Persistent. > > Handle<Object> x > > ... // x is know to be a persistent handle. > > Persistent<Object>(x).ClearWeak(); > > In the following sample the callback XXXCallback will never be called. > > void XXXCallback(v8::Persistent<v8::Value> handle, void*) { > printf("XXX\n"); > handle.Dispose(); > } > > void ClearWeak(v8::Handle<v8::Object> handle) { > v8::Persistent<v8::Object>(handle).ClearWeak(); > } > > > void main(...) { > v8::HandleScope scope; > > ... // Create and enter context. > > v8::Persistent<v8::Object> handle; > { > v8::HandleScope scope; > handle = v8::Persistent<v8::Object>::New(v8::Object::New()); > handle.MakeWeak(NULL, XXXCallback); > } > ClearWeak(handle); > > .. // More stuff eventually causing GC. > } > > Regards, > Søren > > On Tue, Dec 1, 2009 at 12:16, Abdulla Kamar <[email protected]>wrote: > >> I assumed that you could construct a persistent directly, as the header >> has the following statement for the persistent constructor that takes a >> handle: >> >> "Casts" a plain handle which is known to be a persistent handle to a >> persistent handle. >> >> The cast for a persistent takes a persistent, and the persistent construct >> that takes a handle requires is explicit, so I did the following: >> >> v8::Persistent< v8::Object > persistent( v8::Object::Cast( *value ) ); >> v8::Persistent< v8::Object >::Cast( persistent ).ClearWeak(); >> >> >> But that doesn't seem to work. Instead, I've just set the pointer stored >> in the object to null, which seems to work for now but feels like a hack. >> >> -- >> Thank you >> Abdulla >> >> -- >> v8-users mailing list >> [email protected] >> http://groups.google.com/group/v8-users >> > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users > -- Thank you Abdulla -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
