On Thu, May 31, 2012 at 1:05 PM, Tony Huang <cnwz...@gmail.com> wrote: > According to the document, Local<> handles will be disposed at that time, > but let's look at the following code snip: > void SayHello() { > HandleScope scope; > > Local<Value> someValue = GetValue(); > } > In this case, at the end of SayHello, the object someValue as well as scope > object will be disposed. It's C++ scope behavior, so what else will be > disposed while disposing the scope object? Is the object referenced by > "someValue"? >
Hi Tony, v8 objects referenced *only* by Local<> handles get GCed when all local handles go out of scope. In this case, if the value returned by GetValue() has only someValue referring to it, it will get GCed the next time the GC runs after SayHello() is done executing. Every creation of a HandleScope adds a HandleScope to the top of the scope stack. When new Local<>s are created, they 'belong' to the top scope. When 'scope' goes out of C++ scope, then it's destructor is invoked, from where v8 will decide which Local<>s to delete. An object referenced by one (or more) Persistent<> handles will not be GCed until explicitly told to do so. This is useful for preserving JS callbacks across C++ function boundaries and so on. I hope that helps. Best, Nikhil