15 June, 2006

IE AJAX memory leak

We already know about IE memory leak pattern. It's a matter of garbage collection between JS objects and DOM objects.
Did you know about IE HttpRequest memory leak ??
It seems that there is the same symptom with HttpRequest object instanciation. In IE, that objetc is not JS native. It is an ActiveXObject. So that might be the cause.
I have recently faced important memory leaks in our new AJAX application. However, I had my own implementation working well for breaking DOM and JS cycling reference. The point was that my HttpRequest objets where refering to a higher level JS object that contained an array with references to these HttpRequest objets. So I had a cycling reference between standard JS object and ActiveXObject. I did the same breaking reference tool and it all disappeared!


Anonymous said...

Could you share your solution?

Nicolas Faugout said...

Of course !
I can't share my code because it's part of a bigger component and I would spent more time explaining the folk around the hack than the hack itself.
So let speak about the way to do it.
Suppose you have an object which has an attribute which is an XMLHttpRequest object :
myObj = {
request : new ActiveXObject('Microsoft.XMLHTTP'),
something : 'else'
On the onunload event of window, you should unmap your object from the AJAX object like this :
window.onunload = function() {
This way, the JS garbage collector will delete your object and the IE ActiveX garbage collector will do the same with the AJAX object.