In the past, Internet Explorer had some problems with links between regular JavaScript variables and DOM objects. So, if I remember correctly, a circular link like this
var e = document.createElement('div'); var x = { elementReference: e }; e.jsReference = x;
will not be garbage collected even if there were no other references to e
and x
. This is because IE used various garbage collection methods for the DOM and JavaScript elements.
Now I figured this problem was already fixed in IE of higher versions, but maybe it is not. Try to find all such problematic links and manually remove them if you no longer need them.
e.jsReference = null; x.elementReference = null;
Edit: Test in IE 8
I wrote this simple test web page.
<html> <head> <title>Leak test</title> <script> function leak() { var e = document.createElement('div'); var x = { elementReference: e }; e.jsReference = x; } function test() { for (var i = 0; i < 10000; i++) leak(); alert('Done'); } </script> </head> <body> <input type="button" value="test" onclick="test();" /> </body> </html>
I tested this in IE 8, since IE 9 is not installed on this computer. However, it can still be relevant, as it shows that the problem was still present even in quite recent versions of IE and thus it can persist even in IE 9.
I opened the page and looked at the memory usage. Each time you press the button, memory consumption has increased by several MB. After updating the webpage, absolutely nothing happened. After closing IE, memory usage returned to its original state.
You can try this for yourself in IE 9. Of course, you probably do not allocate 10,000 circular references of objects to your code, but you probably create larger objects that may contain some circular reference that you have not yet found.