On Sun, Aug 16, 2009 at 1:11 PM, Stephan Beal<[email protected]> wrote:
> On Sun, Aug 16, 2009 at 6:18 AM, husam <[email protected]> wrote:
>>
>> Handle<Value> setup()
>> {
>>    HandleScope handle_scope;      <========== The code seems to crash
>> here
>
> i've had many, many cases of handlescope crashing, both in DLLs and out, and
> when i see an unexpected crash in v8, the first thing i do is comment out
> the nearest handlescope... normally that works (for reasons i don't
> understand).

One important thing to note about returning Handles out of
HandleScopes is that you have to use the
HandleScope::Close(Local<Value>) method to let a single Handle
"escape" the HandleScope destructor:

   Handle<Value> Setup() {
     HandleScope scope;
     Handle<Value> result = ...
     return scope.Close(result);
   }

Without the scope.Close(result) call, the destructor for scope would
release its reference to the result Handle just as it is being
returned. The caller of Setup() cannot use the returned handle after
that -- there is no telling what it contains or if the memory cell
used by the result Handle is already being re-used by another
allocated Handle.

In general, it's not a good idea to use too few HandleScopes because
that allows Handles to build up in outer HandleScopes and that may
cause memory leaks. Remember that Handles are only deallocated when a
HandleScope is destructed -- and the V8 object referred to by a Handle
cannot be reclaimed until all references to it from Handles are gone.

Cheers,
Kasper

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to