I had to do two things:

re-assign the variable holding my test object to another (delete was  
not enough)
collect the garbage explicitly

static void CollectGarbage (void)
{
        syslog (LOG_NOTICE, "collecting garbage");

        TryCatch tryCatch;

        Local <Context>         currentContext  (Context::GetCurrent ( ));
        Local <Object>          global          (currentContext->Global ( ));
        Local <Value>           gc              (global->Get (String::New 
("gc")));
        Local <Function>        gcFunc          (Function::Cast (*gc));

        (void) gcFunc->Call (global, 0, NULL);

        syslog (LOG_NOTICE, "collected garbage");
}

(This depends on the --expose-gc flag.)

Interestingly, I don't seem to use tryCatch, having declared it. Hmmm.

Pete Gontier <http://pete.gontier.org/>



On Oct 19, 2008, at 4:32 PM, Anthony Shipman wrote:

>
> I've got code to create a JS object that wraps a C++ object.
> I'm using a weak pointer from the C++ object to the JS object to  
> detect when
> the JS object is collected so that I can delete the C++ object.
>
> I can't yet demonstrate that the C++ object is deleted. I wrote a  
> simple loop
> in JS
>
> function f()
> {
>    for (i = 0; i < 1000; ++i)
>    {
>       new jfx.ByteBuffer();
>    }
> }
>
> and run v8 with the flags
>    --log_handles --gc_interval=10 --trace_gc --gc_global
>
> I get debugging messages
>
> constructed byte buffer 0x8a1e0e8, isWeak = 1
> 0x8a1e0e8: isWeak=1, isNearDeath=0
> Mark-sweep 0.4 -> 0.4 MB, 20 ms.
> constructed byte buffer 0x8a440f8, isWeak = 1
> 0x8a1e0e8: isWeak=1, isNearDeath=0
>
> The weak pointers are never marked as NearDeath.
>
> From v8.log I get
>
> GlobalHandle::MakeWeak,0x8a538b4
> GlobalHandle::MakeWeak,0x8a538b4
> markcompact,begin,2,797574,1224457984667
> markcompact,end,2,809572,1224457984679
> scavenge,begin,2,809572,1224457984679
> scavenge,end,2,810572,1224457984679
> GlobalHandle::MakeWeak,0x8a538b4
>
> so you'd think that if the JS objects were no longer referenced then  
> I would
> see them deleted.
>
> So what do I have to do to generate garbage in scripts if the above  
> for-loop
> doesn't do it.
>
> -- 
> Anthony Shipman                    Mamas don't let your babies
> [EMAIL PROTECTED]                   grow up to be outsourced.
>
> >


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

Reply via email to