[webkit-dev] A question regarding to JavaScriptCore's garbage collection mechanism.

Zhe Su james.su at gmail.com
Tue Mar 17 01:46:17 PDT 2009


Hi,
  Recently I encountered a weird issue regarding to JavaScriptCore's garbage
collection mechanism. See following javascript code:

function TestNativeObject(s) {
>   var cb = function() {
>   };
>   cb.call(s);
> }
>
> function Test() {
>   var s = new NativeObject();
>   TestNativeObject(s);
>   s = null;
>   CollectGarbage();
> }
>
> Test();
>

In above code, NativeObject is a class object defined in C++ code, it can
track the lifetime of its instances. CollectGarbage() is a global method
registered from C++ code, which just call JSGarbageCollect() to do garbage
collection forcely. Ideally, the NativeObject created in Test() should be
destroyed when calling CollectGarbage(). But unfortunately, it won't. The
tricky thing is: removing the line "cb.call(s)" in TestNativeObject()
function solves this issue, though cb is just an empty function.

This code was tested against webkit svn. Anyone can help me explain this
behavior? Is it a bug of JavaScriptCore?

Regards
James Su
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090317/93b46be9/attachment.html>


More information about the webkit-dev mailing list