jQuery,.empty()和内存 [英] jQuery, .empty() and memory

查看:61
本文介绍了jQuery,.empty()和内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序(ASP.NET MVC)显示了一个页面,该页面以一定的时间间隔不断加载数据.

my application (ASP.NET MVC) shows a page which loads data constantly, at certain intervals.

jQuery脚本调用一个控制器,该控制器根据某些条件呈现一个不同的局部视图.

The jQuery script calls a controller and this one renders a different partial view, based on certain conditions.

此局部视图通过jQuery附加到DOM;以前的元素可以通过empty()方法删除.

This partial view is the appended to the DOM with jQuery; previous elements are removed with the empty() method.

        $(document).ready(function() {
        var ScheduledAction = function(func, times, interval) {
            var ID = window.setInterval(function(times) {
                return function() {
                    if (times > -1) {
                        if (--times <= 0) 
                            window.clearInterval(ID);
                        }
                    func();
                }
            } (times), interval);
        };
        ScheduledAction(function() {
            LoadAppointments();
            }, -1, <%=Model.RefreshTimeout %>);
    });

    function LoadAppointments()    {

        $("#AppointmentsList").empty();
        $('#loading').html("<img src='Images/bigloader.gif' />");
        $.get(UrlAction, 
            function(data) {
                if (data != '') {
                    $('#AppointmentsList').append(data);
                    $('#loading').empty();
                   } 
                else {
                    $('#loading').fadeOut(3000, function() { $('#loading').empty(); });
                   }
            });
        }  

控制器(UrlAction)返回局部视图.对于每个往返,局部视图是不同的.一旦局部视图仅包含图像.在另一种情况下是具有一些信息的div.

The controller (UrlAction) returns a partial view. For Each roundtrip the partial view is different. Once the partial view contains just an image. In the other situation is a div with some infos.

我已经意识到,一天后浏览器将加载600Mb的内存. 我在做什么错了?

I've realized that after one day the browser loads something like 600Mb of memory. What am I doing wrong?

推荐答案

这可能只是jQuery中的错误?

It could just be a bug in jQuery?

在所有版本的IE中,我都遇到过类似的问题,主要是随着时间的推移处理大量的AJAX请求.

I've run into similar issues, mostly when doing tons of AJAX requests over time, in all versions of IE.

此错误描述了该问题,并提供了一个简单的jQuery修补程序来解决该问题:

This bug describes the problem and a simple patch to jQuery that should fix it:

http://dev.jquery.com/ticket/6242

这篇关于jQuery,.empty()和内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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