【问题标题】:cells property leaks memory on Internet Explorer?单元格属性在 Internet Explorer 上泄漏内存?
【发布时间】:2013-02-21 15:22:14
【问题描述】:

Microsoft documentationW3C 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


    【解决方案1】:

    rowcell DOM 对象有 circular references,因为它们在不在文档树中时引用自己:

    var row = document.createElement('tr');
    row.appendChild(cell);
    

    此外,对cells 属性的调用返回一个IHTMLElementCollection

    IE10有内存泄漏bug:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多