Anton,

I updated the snippet to try replicating your suggestion, but was
still unable to get the WeakReferenceCallback to be invoked.

https://gist.github.com/908831

I would have expected the callback to have been invoked when GC is
forced the first time after making the object handle weak. Is the
Context is holding a strong reference to the object?

cheers,
Charles


On Apr 8, 5:13 am, Anton Muhin <[email protected]> wrote:
> Charles,
>
> Contexts have complicated lifetime.  If you just curious how weak
> handles work, you'd better play with simpler objects.
>
> Handle goes near death state when it found out it references weakly
> reachable object.  You're callback is never invoked as v8 retains the
> context (it's a current context) and hence strongly reachable from
> inside v8.  Value is base type, so everything is an instance of Value.
>
> Please note that you have a bug in your code: your weak callback must
> either dispose the handle passed or revive it.
>
> And, just in case, most of objects are created and returned back in
> Local handles.  Those handles live as long as handle scope to which
> they belong and retain the object.  Thus the code:
>
> HandleScope hs;
> Persistent p = Persistent::New(Object::New());
> p.MakeWeak(...)
> // Force GC
>
> will never trigger weak callback as l is alive and it retains the
> object.  The right way:
>
> Persistent p;
> {
>   HandleScope hs;
>   p = Persistent::New(Object::New());}
>
> p.MakeWeak(...)
> // Force GC
>
> hth and yours,
> anton.
>
>
>
>
>
>
>
> On Fri, Apr 8, 2011 at 1:59 AM, Charles Lowell <[email protected]> 
> wrote:
> > Hi,
>
> > I'm having trouble understanding when a Persistent handle is
> > considered "Near Death", and when exactly a weak reference callback is
> > invoked. Consider the following code:
>
> >https://gist.github.com/908831
>
> > It appears that the WeakReference Callback is never invoked.
>
> > I guess my questions are
>
> > 1) Why is it never considered near death? given that there is only one
> > reference to it which is weak.
>
> > 2) why isn't the PrintlnWeakReferenceCallback ever invoked?
>
> > 3) WeakReferenceCallbacks take a Persistent<Value> as a parameter.
> > What if, as in this case, the object is not a Value?
>
> > cheers,
> > Charles
>
> > --
> > 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

Reply via email to