IE JavaScript Memory Leak
The welcome page text animation had a big memory leak. I found all sorts of solutions on the web to resolve JavaScript leaks that result from result bad garbage collection of circular references, but my issue seems to be unique. I've found that within callback functions from timers set by setTimeout or setInterval, use of innerHTML whatsoever will grow your process memory.
That all there is to it. The workaround I had to apply was to use the innerHTML property within timer calls. Here is a demonstration of the bug. Watch your process memory grow while the "innerHTML Loop" is running, however remain constant if you start up the "innerText Loop." The relevant version of IE that I'm aware of is 6.0.
function leak()
{
document.getElementById("test").innerHTML = 'foo';
}
var timer = setInterval(leak, 100);
That all there is to it. The workaround I had to apply was to use the innerHTML property within timer calls. Here is a demonstration of the bug. Watch your process memory grow while the "innerHTML Loop" is running, however remain constant if you start up the "innerText Loop." The relevant version of IE that I'm aware of is 6.0.
1 Comments:
I can no longer reproduce this on IE 6.0.2900.2180.xpsp_sp2_gdr.050301-1519.
Post a Comment
Links to this post:
Create a Link
<< Home