In handling the destruction of weak objects, I added Garry's patch to
force collection of weak objects (i.e. forcing a
"i::Heap::CollectAllGarbage()" at the end of the program (Thanks Gary!
That was very helpful). This allowed me to verify that the destructor
callback logic was working. At the same time, I discovered something
that is bothering me. In essence, it seems that weak objects that are
declared in the global scope of a script are never marked as PENDING
by the garbage collector. Here is a simple example:


var globalWeak = new MyWeakType();
function Test()
{
    var weak1 = new MyWeakType();
    weak1.value = 3;
}
Test();

The destructor callback on weak1 is correctly invoked when the
CollectAllGarbage() occurs. But the globalWeak callback never happens,
even when I dispose of the current context and of the global object.
As a result, I end up with a dangling peer.

I stepped through the collector code to get a clearer idea of what is
going on. What I saw is that the collector never marks the globalWeak
var as PENDING, thus the callback is never invoked. I realize that
this is happening because the globalWeak var never falls out of scope.

Nonetheless, it would seem logical to assume that when the Global
Object is disposed of, all global vars should be dereferenced, thus
allowing the GC to invoke the destructor callback.

Or did I miss something obvious?  Would not be the first time :-)...

Frederic





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

Reply via email to