阿贾克斯内存泄漏 [英] ajax memory leak

查看:96
本文介绍了阿贾克斯内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到使用ASP.NET AJAX和jQuery的组合,在IE和Firefox缓慢的内存泄漏。我的情况下是非常相似的这里所描述的:<一href="http://stackoverflow.com/questions/276087/$p$pventing-ajax-memory-leaks">http://stackoverflow.com/questions/276087/$p$pventing-ajax-memory-leaks除了使用jQuery和asp.net AJAX,不是protyotype:我有一个使用一个定时器刷新每60秒一个UpdatePanel显示数据的网页。在被要求每一个局部回传的AJAX页面加载的JavaScript功能,我重新绑定事件,因为他们失去了在asp.net局部回传:

I am experiencing a slow memory leak in both IE and Firefox using a combination of ASP.NET AJAX and jQuery. My scenario is very similar to the one described here : http://stackoverflow.com/questions/276087/preventing-ajax-memory-leaks except using jquery and asp.net AJAX, not protyotype: I have a webpage displaying data in an UpdatePanel that is refreshed every 60 seconds using a timer. in the AJAX javascript pageLoad function that is called on every "partial postback", I re-bind events because they are lost in the asp.net partial postback:

function pageLoad(sender, args) {
    $("#item").unbind();
    $("#item").hover(
        function() {
            // do something
        },
        function() {
            // do something
        });
}

所以这就是所谓的每60秒。难道这单独的内存泄漏的原因是什么?

so this is called every 60 seconds. Could this alone be the cause of a memory leak?

推荐答案

做到这一点,而不是:

$(function() { //.ready shortcut...
  $("#item").live("hover",
    function() {
        // do something
    },
    function() {
        // do something
    });
 });

请注意,此需要的jQuery 1.4.1 ,但行为在内存方面完全不同。它安装在整个DOM观看的事件的泡沫,而不是附加一个新的事件,每个对象需要的资料每60秒插入。

Note, this requires jQuery 1.4.1, but acts entirely different in terms of memory. It attaches to the entire DOM watching for the event to bubble instead of attaching a new event to every object your're inserting every 60 seconds.

这篇关于阿贾克斯内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆