I'm having trouble cleaning up garbage in V8. First, my Javascript is as follows:
var bigstring = "ASD";
for (var b = 0; b < 20; b++) {
bigstring = bigstring + bigstring;
}
trace("bigstring " + bigstring.length);
function frame() {
// generate some garbage
var junkArray = [];
for (var i = 0; i < 1000; i++) {
junkArray.push(i + bigstring);
}
}
From C++, I'm running a loop:
frame
.while(!V8::IdleNotification()) {};
The expected result is that each iteration, the junkArray
garbage is collected. After all, IdleNotification
only returns true when "V8 has done as much cleanup as it will be able to do" (doc).
In fact, the garbage is only cleaned up* approx. every 100 iterations. Am I missing a step? Is junkArray
for some reason not garbage immediately after frame
?
*Determined by comparing before-and-after heap usage
Instead of v8::V8::IdleNotification
, try using v8::Isolate::LowMemoryNotification
. As far as I can tell that's the only way to get recent V8 builds to do a full GC via the public API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With