Javascript garbage collection of typed arrays in Chrome

Check out the following javascript. I would think that allocating in a loop would allow garbage collection, preventing heap overflows. It does this correctly in Firefox, however in Chrome (tested on OSX) the fragment resets the open tab after several iterations.

    for (var i = 0; i < 1024; ++i) {
            // Allocate a 16mb buffer
            var buffer = new Float32Array(1024*1024*4);

            // Try to explicitly mark it for free by either
            delete buffer;
            // or
            buffer = null;

            console.log(i);
    }

This script alone is not all that useful. But I'm trying to optimize my Javascript application to use less memory. Therefore, I would like to receive your opinion. Is this a bug in Chrome? Do you know about workarounds to explicitly cause garbage collection during code execution (in FF and IE they seem to exist)? Thank!


: Chrome Inspector " ". 7- " " . , GC Javascript? , , Javascript?

+5
2

, , , .

, , , , :

var i = 0;
function allocateArray() {
    var buffer = new Float32Array(1024*1024*4);
    if (++i < 1024) {
        setTimeout(allocateArray, 0); // Post the next call to the run loop
    }
}
allocateArray();
+2

, GC . , . Chrome, , .

Chromium , . https://code.google.com/p/chromium/issues/detail?id=232415

, Chrome .

, ( )

- , .

0

All Articles