On Fri, Oct 22, 2010 at 16:24, Stephan Beal <[email protected]> wrote:
> On Fri, Oct 22, 2010 at 4:15 PM, Rasmus Andersson <[email protected]> wrote:
>>
>>  void *data = NULL; // points to something in reality
>>  phandle.MakeWeak(data, &WeakCallback);
>
> It would really surprise me if MakeWeak() does anything useful when passed a
> NULL pointer. If you just need a pointer to test with, the approach i like
> is:
> static int x = 42;
> void * data = &x;

I am passing a pointer to some heap allocated memory in my actual
implementation. I just removed that part in the mail. Sorry for the
confusion.

>>
>> The "Handler" gets called as expected, but "WeakCallback" is never
>> called.
>>
>> Any ideas?
>
> AFAIK, v8 never guarantees that the WeakCallback will _ever_ be called. Even
> when v8 shuts down, it might just quit without calling the destructors. It
> was explained once on this mailing list (a year or more ago) that that is
> for performance reasons in the Chrome browser, to avoid a long cleanup phase
> when the app is exiting and will be cleaned up by the OS. (i don't agree
> that the behaviour is correct, because it fails to recognize that
> destructors must be called for proper cleanup, but it's not my code.)

I've created a test program which calls createAndCallAFunction() 1000
times per event loop, thus reaching ~1GB residential memory within a
few seconds. I guess at least one of the millions of objects created
should be GC:ed?

After hitting approx. 1GB res,  memory usage stabilizes, so I guess v8
DO reuse memory (so no refcounter leak I guess).

Most examples (including Ryan Dahls/Node.js ObjectWrapper) operate on
Object and ObjectTemplate, but in my case it's a Function (which is a
subclass of Object, but have a separate Template class).

>
> --
> ----- stephan beal
> http://wanderinghorse.net/home/stephan/
>
> --
> 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

Reply via email to