IE memory leak and eval with jQuery

2019-07-07 06:42发布

I've created a page which needs to have its elements updated according what's happening with the data in our database. I'd like to know what do you think about this approach using eval, I know it's risky but in my case it was the fastest way.

$('.updatable').each(function () {
        var data;
        data = 'ViewObjectId=' + $(this).attr('objectid');

        $.ajax({
            async: true,
            url: '/Ajax/GetUpdatedViewObjectDataHandler.ashx',
            data: data,
            type: 'POST',
            timeout: 10000,
            success: function (data) {
                $.each(data, function (index, value) {
                        eval(value);
                });
            }
        });

Now the issue I have is when the page is loaded, for each 10 seconds the page is updated, until here it's perfect.

After each round of updates, my Internet Explorer steal some memory, and it gets the whole machine memory after some hours, terrific.

What would you do in this case? Some other update approach is recommended? Or even, is there something you think I could do to avoid this memory leak?

1条回答
Luminary・发光体
2楼-- · 2019-07-07 07:27

Found the answer here: Simple jQuery Ajax call leaks memory in Internet Explorer

THE SOLUTION:

 var request = $.ajax({ .... });

 request.onreadystatechange = null; 
 request.abort = null; 
 request = null;

JQuery doesn't do that and the memory never releases.

jQuery version 1.4.2.

Now it's working like a charm.

查看更多
登录 后发表回答