Anton,

Thank you so much for your reply, it cleared up a lot, and also thanks
for spotting the bug. I wasn't aware of that behavior.

I'll do the basic experimentation on Objects, but I guess my next
question is what exactly does it mean for a Context to be a "current",
and how does a context become "uncurrent" and therefore eligible for
garbage collection? This is an important question because my context's
global object can hold strong references to external objects.

As an aside, in v8.h Context does not extend Value, so how would I
cast the Value back to Context?

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