On Thu, Oct 6, 2011 at 5:41 PM, Ondřej Žára <[email protected]> wrote: >> >> The Handle you pass in is not stored. In fact, looking at the source for >> SetInternalField, the handle you pass in is dereferenced into the raw >> Object* and that is stored instead. >> So doing: >> A->SetInternalField(0, v8::Persistent<v8::Object>::New(B)); >> is actually leaking a persistent handle to B, since SetInternalField is >> not holding onto the handle at all and there is no way to get that specific >> handle back. >> Another clue about this is that GetInternalField returns a Local, so it's >> actually generating a new handle every time you look up the value, rather >> than returning exactly the Handle you originally passed in. > > Aaah! Thanks a lot for the explanation. > > Does this also mean that I do not need to empty the internal field, when A > gets destroyed?
You don't need to. References from v8::Object to v8::Value, including those in internal fields, are subject to precise tracing by the garbage collector. If A is no longer reachable and A had the last/only reference to the object in its internal field, then that object is now unreachable, too, so the GC will take it. Handles are only necessary when you store references to objects in places inaccessible to the GC: the C++ stack (e.g. during a callback) or the C++ heap (a more permanent in a global or a C++ data structure). Think of the JS heap (where all the v8::Values live) as a connected graph "in the middle" that is completely managed by the GC. You need to help the GC when you point into this graph from the "outside". Matthias > > > O. > > >> >> matt >> >> -- >> 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 -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
