See this response I had posted on nodejs.
http://groups.google.com/group/nodejs/browse_thread/thread/49e016231cec8545/c59858db7ab4079f?lnk=raot&pli=1

Specifically, Stephen Beal's wiki has a lengthy, detailed article
written on finalization, destructors, & c++/js interaction.

-L

On Saturday, October 23, 2010, Rasmus Andersson <[email protected]> wrote:
> On Sun, Oct 24, 2010 at 00:47, Marco Rogers <[email protected]> wrote:
>> Okay so does this mean that if you actually pass the handle back to js space
>> then it does become eligible for GC?  What you set it to a property of an
>> object from js space?
>
> I don't think so. I built a test program which did just that.
>
> 1. Created a function in C-land,
> 2. Exposed it to a v8 script
> 3. Ran the script which called the function
>
> After hitting 1GB res. memory, none of the million instances had been
> released (yes, I yielded to v8 "IdleNotification" so GC could take
> place).
>
> I think you need to _create_ the instance in js-land for it to be
> subject to GC. If you define your own function type using
> FunctionTemplate and providing a custom initializer (usually a
> Handle<Value> New(const Arguments& args)), then when such an object is
> created in js-land, |args.Holder()| will contain an object which has
> been allocated by v8 and should be subject to GC. The problem seems to
> arise when _you_ create the "Holder" object.
>
>> I've been using the v8 API for a while now and I understand the basics (and
>> a bit more). I'm just trying to make sure I understand this particular
>> gotcha and how to avoid it.
>
> Same thing here. Would really appreciate some clarification from
> someone into v8 core dev. :)
>
>>
>> :Marco
>>
>> On Sat, Oct 23, 2010 at 6:40 PM, Rasmus Andersson <[email protected]> wrote:
>>>
>>> On Sat, Oct 23, 2010 at 23:41, Marco Rogers <[email protected]>
>>> wrote:
>>> > Anton, what do you mean by "API functions.."?  Which part of his above
>>> > example are you referring to?  I admit I'm still not sure what's wrong
>>> > with what Rasmus is doing.
>>>
>>> I believe what Anton is saying is that an object created in C-land
>>> will not be subject to GC.
>>>
>>> Here, we create (i.e. allocate) a Function object using the C++ API:
>>>
>>> HandleScope scope;
>>> Local<Function> fun = Local<Function>::New(...);
>>> Persistent<Function> phandle = Persistent<Function>::New(fun);
>>> phandle.MakeWeak(data, &FinalizationCallback)
>>>
>>> If I understand Anton correctly, this function will never be garbage
>>> collected thus FinalizationCallback never called. Anton, is that
>>> correct?
>>>
>>> And the case v8 create the object for us:
>>>
>>> HandleScope scope;
>>> Local<Value> v = EvalHelper("function(){}");
>>> Local<Function> fun = Local<Function>::Cast(v);
>>> Persistent<Function> phandle = Persistent<Function>::New(fun);
>>> phandle.MakeWeak(data, &FinalizationCallback)
>>>
>>> But in this case FinalizationCallback will be called.
>>>
>>> Is this correct?
>>>
>>>
>>
>> --
>> Marco Rogers
>> [email protected]
>>
>> Life is ten percent what happens to you and ninety percent how you respond
>> to it.
>> - Lou Holtz
>>
>> --
>> v8-users mailing list
>> [email protected]
>> http://groups.google.com/group/v8-users
>
>
>
> --
> Rasmus Andersson
>
> --
> 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