Hi Tony, You are correct.
Nikhil On Thu, May 31, 2012 at 2:34 PM, Tony Huang <cnwz...@gmail.com> wrote: > Hi Nikhil, > > Thank you for your help. > > So may I consider this in this way: > > 1) Objects who is referenced by any Handle will not be disposed. > 2) Objects referenced by Local<>s will be add to a list hold by the > HandleScope object, and while disposing HandleScope object, it will check > all objects in this list whether it should be disposed. And this design is > for objects whose lifecycle is very short to be released immediately to > improve the performance and memory usage. > 3) Persistent handles will not add the object to the list of HandleScope, > and the lifecycle of that object is relatively longer, and frequently > disposing HandleScope objects will not check these objects, and as a result, > it will improve performance. > > Am I right? > > Thank you! > Best Regards. > > On Thu, May 31, 2012 at 4:20 PM, Nikhil Marathe <nsm.nik...@gmail.com> > wrote: >> >> 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 > > > > > -- > ------------------------------------------------------ > Tony Huang cnwz...@gmail.com > wz...@hotmail.com > wz...@vip.sina.com