Hello everyone,

I've been embedding the V8 engine into FreeSWITCH, to be able to use 
JavaScript within FreeSWITCH. I'm more or less finished, but I have found a 
strange thing with weak callbacks. I do handle the cleanup now anyway, 
since I store the C++ instances in a separate list which cleans up 
everything still alive after JS exectution - but I would still like to 
understand why this happens.

Consider the following code example in JS;

---

var test = new DB();

function callback(dataRow) {
    // Do something
}

test.exec('SELECT * FROM test', callback);

---

In this case CoreDB is a class that I've implemented, and the C++ instance 
for this class has a weak callback that should happen when the object 
("test") is GC'd.
The callback function is stored in the C++ instance as a 
Persistent<Function>.

If I do a Persistent<Function>.Reset after I've used the callback, the weak 
callback will happen, but if the persistent function is still "alive", it 
will never happen.
After execution I force GC to run, so I know the object should be cleaned.

I just don't understand why the GC won't cleanup an object because it 
internally holds a reference to the JS function "callback". If something 
within that JS function would reference the object "test" I would at least 
understand why, but in this case I see no reason.

I've also tried storing the function as a "Function *func" inside the C++ 
instance - this actuelly does work properly, but I'm not sure if I always 
can asume that this reference will be valid during the entire JS execution?

/Peter

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to