开发者

IE memory leak - settimeout, repeatedly setting innerHTML

I have an application which redraws a portion of the page every 60 seconds. The redraw causes major memory leaks in IE.

I tried using both settimeout/setinterval to set the redraw timer.

I also tried many of the tips suggested like

  • setting innerHTML = '' instead of using jquery remove/empty.
  • Removing all event handlers before redrawing HTML.
  • Deleting all child nodes before emptying the parent container.
  • Setting outerHT开发者_运维问答ML to clear instead of innerHTML

In spite of all these I can see a big memory leak. MS KB article seems to indicate that IE 8 is inherently leak and we need to apply a hotfix: http://support.microsoft.com/kb/975623

But, I have seen this issue in IE7 as well and in firefox to a very small level.

Any help would be greatly appreciated.

Thanks, Suchin


All the options you mentioned are worth the shot, have you also tried adding the DOM element first, and then setting the innerHTML later?

Here is an example http://ecmascript.stchur.com/blogcode/ie_innerhtml_memleak/noleak.html

And the guy's solution

   // Add the element to the DOM first, and /then/ set .innerHTML to 
   // prevent memory from leaking.
   document.body.appendChild(elem);
   elem.innerHTML = str;

How did you remove all the handlers? did you use something like Crockford's purge solution? http://javascript.crockford.com/memory/leak.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜