3 ms·
> The browsers struggled with this for years. Arguably, they still do. function f() { var some = []; while(some.length < 1e6) { some.p
by paulddraper 8y ago
> The browsers struggled with this for years.
Arguably, they still do.
function f() {
var some = [];
while(some.length < 1e6) {
some.push(some.length);
}
function g() { some; }
return function() {};
}
var a = [];
var interval = setInterval(function() {
var len = a.push(f());
if(len >= 500) {
clearInterval(interval);
}
}, 10);
uses a very large amount of memory in all browsers.
function f() {
var some = [];
while(some.length < 1e6) {
some.push(some.length);
}
function g() { some; }
}
var a = [];
var interval = setInterval(function() {
var len = a.push(f());
if(len >= 500) {
clearInterval(interval);
}
}, 10);
uses very little.
https://stackoverflow.com/questions/19798803/how-javascript-closures-are-garbage-collected https://stackoverflow.com/questions/19798803/how-javascript-...
https://blog.meteor.com/an-interesting-kind-of-javascript-memory-leak-8b47d2e7f156 https://blog.meteor.com/an-interesting-kind-of-javascript-me...
- mras0 8y agoFor the record I'm pretty sure my implementation uses a very large amount of memory in both cases as I'm not doing anything to avoid it (like escape analysis).