IE 中的 jQuery DOM 操作内存泄漏
我们在 IE 上进行 DOM 操作时发现了严重的内存泄漏。基本上,我们正在这样做:
function updateTable(){
$.get('table.jsp', {}, function(data){
$('#dataTableContainer').empty().html($(data).find('#dataTable'));
setTimeout(updateTable, 1000);
});
}
每秒重复一次该方法。从我们所看到的情况来看,该方法在 jQuery 1.7.1 中每 10 秒就会泄漏大约 1Mb 的内存(对于旧版本,情况更糟)。
我们做错了什么吗?我们尝试了 stackoverflow 中已经发布的几种解决方案(例如 带有 DOM 删除的 jQuery 内存泄漏)但没有任何效果。
We found a serious memory leak on IE when doing DOM manipulation. Basically, we were doing this:
function updateTable(){
$.get('table.jsp', {}, function(data){
$('#dataTableContainer').empty().html($(data).find('#dataTable'));
setTimeout(updateTable, 1000);
});
}
and repeating that method once every second. From what we were able to see, that method was leaking around 1Mb of memory every 10 seconds with the jQuery 1.7.1 (it was even worse with older versions).
Are we doing something wrong? We tried several solutions already published in stackoverflow (Ex. jQuery memory leak with DOM removal) but none worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
html jQuery 方法 接收一个字符串或函数,而不是像您正在做的那样的查询对象。 html方法替换了内容,因此不需要使用 empty 方法。
Try this:
The html jQuery method receives a string or a function, NOT a query object like you are doing. The html method replaces the content, so there is no need for using the empty method.