3

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?

Fabito
  • 1,165
  • 2
  • 13
  • 30
  • I've removed the eval function and created a new function, but the leak still there. – Fabito Nov 17 '11 at 11:54
  • The problem is in the ajax call: $.ajax( -> I don't know why yet. – Fabito Nov 17 '11 at 17:10
  • According this post, the anonimous calls was generating the memory leaking... http://stackoverflow.com/questions/3617442/jquery-memory-leak-with-repeated-ajax-calls I'm testing and seems to be getting better. – Fabito Nov 17 '11 at 17:23
  • Found the answer here: http://stackoverflow.com/questions/2429056/simple-jquery-ajax-call-leaks-memory-in-internet-explorer – Fabito Nov 18 '11 at 01:27
  • THE SOLUTION: var request = $.ajax({ .... }); request.onreadystatechange = null; request.abort = null; request = null; JQuery doesn't do that and the memory never releases. – Fabito Nov 18 '11 at 01:29

1 Answers1

2

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.

Community
  • 1
  • 1
Fabito
  • 1,165
  • 2
  • 13
  • 30