IE 中的 jQuery DOM 操作内存泄漏

发布于 2024-12-26 16:19:31 字数 527 浏览 7 评论 0原文

我们在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平安喜乐 2025-01-02 16:19:31

试试这个:

function updateTable(){
    $.get('table.jsp', function(data){
        var dt = $(data).find('#dataTable').html()
        $('#dataTableContainer').html(dt);
        setTimeout(updateTable, 1000);
    });
}

html jQuery 方法 接收一个字符串或函数,而不是像您正在做的那样的查询对象。 html方法替换了内容,因此不需要使用 empty 方法。

Try this:

function updateTable(){
    $.get('table.jsp', function(data){
        var dt = $(data).find('#dataTable').html()
        $('#dataTableContainer').html(dt);
        setTimeout(updateTable, 1000);
    });
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文