I created a web page that makes an Ajax call every second. In Internet Explorer 7, it leaks memory badly (20 MB in about 15 minutes).
The program is very simple. It
I encountered the same issue and had been stumped all morning ... until a few moments ago. The problem is a circular reference that is created when you set the onreadystatechange
handler, that IE isn't smart enough to break. The solution, therefore, is to break it explicitly. However, obviously you can't do it from within the handler itself (though it would be convenient if you could!).
The magic statement:
delete request['onreadystatechange'];
You need to keep a record of each XMLHttpRequest
object for which you set onreadystatechange
. Then, at some point after readyState
goes to 4, do your magic on the object. If you are already performing a repeated AJAX poll, the logical place to check for requests to clean up would be in the same polling loop. I defined a simple RequestTracker
object to manage my requests.
This worked for me; I verified that it solved the leak. Here's one link in particular that led the way (I would post more, but StackOverflow isn't letting me):