Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE6 Memory Leak on Refresh?

I reload a page every few seconds to get an update from the server, this page can be open and this can happen forever - I am guessing, espcially since this browser is on a remote server which isn't turned off.

I do this:

setTimeout(function () {
        location.href = location.href; // forces a reload from the server
    }, 1000*10*0.5); 

I have noticed that IE6's memory usage keeps increasing and increasing. The page does nothing apart from the refresh and display html.

Why does this happen? How can I over come this problem? I don't want to crash IE6.

Its at 435,000K and it has been about 30 minutes.

Thanks all

Update

Sorry everyone - I do have another function which runs every time the page is loaded:

function recreateTicks(tasks){

 if(tasks!=''){

  var myTicks = tasks.split(',');

  var length = myTicks.length;

  for(var i=0; i<length; i++){

   var element = myTicks[i];

   $('#'+element).attr('checked', true);

  }

 }

}

Anything wrong with the above? Circular reference??

Update 2

The above function is called like this:

<script type="text/javascript">
<!--PHP Generated-->
var tasks = 'ab_1, ab_2, ab_3';
</script>
<script type="text/javascript">
$(document).ready(function(){     
recreateTicks(tasks);
});
</script>
like image 625
Abs Avatar asked Feb 22 '10 17:02

Abs


3 Answers

Are you certain the page doesn't do anything? You don't (for instance) have a few event handlers you've attached to elements? IE is famous for leaking memory if you don't explicitly break the connection between an element and its handler during the unload event. (It's not universal, the handler has to have a reference to something, but it's trivially easy to make it happen -- via a closure, for instance.) Crockford wrote up some info about IE's memory leaks which may be useful to you.

like image 130
T.J. Crowder Avatar answered Nov 10 '22 17:11

T.J. Crowder


Ok, this is slightly controversial, but why not just let IE6 crash?

You can end up putting the majority of your development time into IE6 issues - a rapidly dwindling market at best. While it holds on grimly in the corporate space the remaining users are horribly locked down with lots of poor software anyway. Those IE6 users will increasingly have the perception that their PC setup is sub-standard (and it is).

Why not just let those IE6 users crash? They'll just see their PC get slower and slower, and the error message (when it comes) is an IE one, not an in-page one.

There's lots of value in a 100% customer driven approach to quality, and it's dangerous to start letting these users fend for themselves like this, but the important balance for you is development cost vs reward.

Unless these IE6 users (whose browser crashes all the time anyway) will notice that your app is the problem and have the power to block you selling it then what's the value to you in doubling your development costs?

Finally, if you really want IE6 leak free then don't use jQuery. Write all your Javascript from scratch and watch your scopeing and various IE6 DOM bugs like a hawk. jQuery uses expanded attributes (which always leak in IE6) and hides some of the scope issues that you really need to micro-manage if you want IE6 to not leak.

like image 38
Keith Avatar answered Nov 10 '22 16:11

Keith


IE6 has a terrible time with memory. IE7 has made some improvements, and even more in IE8.

As TJ says, circular references can cause this to happen (a page element is referencing a javascript object that is referencing back to that element).

You can read more about how to mitigate IE leaks, by reading THIS PAGE. You should also check out The JavaScript Memory Leak Detector (written by the Global Products team at Microsoft). It will help you find the leaks, if any.

like image 2
Gabriel McAdams Avatar answered Nov 10 '22 16:11

Gabriel McAdams