【发布时间】:2013-02-21 15:22:14
【问题描述】:
Microsoft documentation 和 W3C documentation 均未提及泄漏。
它发生在动态创建的行上。这对我们来说是个问题,因为我们有一个单页 Web 应用程序,其中的表会通过 ajax 定期更新,最终 iexplore 会消耗所有内存并且 Windows 会死掉。
复制:
function process() {
var row = document.createElement('tr');
var cell = document.createElement('td');
var text = document.createTextNode();
// doesn't matter order of these lines:
row.appendChild(cell);
cell.appendChild(text);
// this leaks on IE8/9:
var x = row.cells;
// this alternative doesn't:
//var x = row.getElementsByTagName("td");
setTimeout(process, 10);
}
process();
http://jsfiddle.net/5wzW2/1/ (jsfiddle 站点在 IE8 上无法运行,因此发布了上面的代码)。
在任务管理器中查看 iexplore 的内存使用情况每分钟增加大约 1 MB。 FF18/Chrome24 中没有。
任何想法为什么,或最好的做法是什么?
Microsoft's bug reporting page 似乎已损坏。我的解决方法是将.cells 替换为.getElementsByTagName("td"),例如在tablesorter 插件中。
【问题讨论】:
标签: internet-explorer debugging memory-leaks cross-browser appendchild