Gregor Kofler wrote:
Quote:
Thomas 'PointedEars' Lahn meinte:
Quote:
Quote:
>>Well, perhaps I'm just suffering some
>>memory-leak-paranoia...
>>
>I think your concern is certainly based on reasonable
>grounds.
>
I've just tried this on FF w/ Firebug:
>
for(var k = 100; --k;) { (function() {
var stack = [], id, counter = 0;
id = window.setInterval(function() {
var s = [];
for(var j = 1000; j--;) {
s.push("xyz", "abc", "def");
}
>
stack.push(s);
console.log(counter);
>
if(++counter 100) {
window.clearInterval(id);
}
}, 100)
})();
}
The memory usage of FF goes up from approx. 76MB to around
290MB, then (after clearing the console) to 77MB, a reload
pushed it again to 290MB before returning to (hooray!) 76MB.
>
It's of course a bit pedestrian, but the GC seems to collect
all the unused stuff properly.
This is a test for a memory leak, and not finding one is good. But I
don't think anyone was expecting to find a memory leak here anyway.
Circular chains of references between pure javascript objects have never
been a garbage collection issue once there are no external references to
any of the objects involved.
You have shown ~2 Megabytes per loop iteration of memory consumption,
and those of us who used 1980's computers, where having 2 Megabytes of
memory would have been unusual, may find that a little shocking. For an
in-page AJAX web application the important question may not only be the
overall garbage collection effectives but also the memory footprint of
the running application, so if that per iteration memory consumption
could be reduced by freeing more objects sooner that may be significant.
You have shown that the outer function gets garbage collected
eventually, but not that it can be garbage collected as soon as its
execution context is finished.
Richard.