开发者

ajax memory leak

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 : 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 ja开发者_如何转开发vascript 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
        });
}

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


Do this instead:

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

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.


Yes, it could be.

The first thing to try would be to take the two functions defined there (if possible) and place them in a higher level so that they are only defined once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜