Hi:
I'm trying to understand how to resolve an IE memory leak that occurs in the following general situation. Basically, if I use a closure inside setTimeout() to call an object instance method repeatedly, in which the method accesses the .innerHTML property of an element to modify it's HTML, a leak occurs in IE. For example:
Code:<div id="numberdiv">holder</div> <script type="text/javascript"> function timemachine(offset){ this.offset=offset this.display() } timemachine.prototype.display=function(){ //Use the innerHTML property to assign rich HTML to an element, in combo with closure- leak in IE! document.getElementById("numberdiv").innerHTML='<p><b>'+this.offset+new Date().getSeconds()+'</b></p>' var _this=this //Closure below, no leak by itself setTimeout(function(){_this.display()}, 1000) } var sample=new timemachine(5) </script>
Apparently it's the closure coupled with the rich HTML assignment that creates the leak. I've tried a few standard techniques to plugging the leak, but nothing has worked. Anyone know of an elegant solution that doesn't require "re-wiring" everything? Any pointers appreciated.



Reply With Quote
I've tried the double closure route, though I must have gotten lost in my own code, because it didn't do anything in halting the perpetual memory increase.





Bookmarks