IE9 memory leak

I notice that in my application, the memory associated with the IE process on Win7 rises by 20-30 MB with every page refresh. As soon as I reached about 1.5 GB, the browser stops responding. I use IE9 and can only reproduce this in IE9. There is no such problem in Chrome, FF, IE7 or IE8. In fact, the problem also does not occur when starting IE9 in compatibility mode.

In particular, I wonder how a memory leak can occur even after a page is refreshed. Has anyone else seen this?

+6
source share
2 answers

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.

+3
source

I'm not sure if this will be your problem, but I also get this IE9 memory leak problem, where memory is constantly growing and growing (about 20 mg per page refresh / change).

If you use Modernizr (this should be fixed now in one of the latest releases, more than 2.5+ I think), but if you are using an older version (and cannot just update it for any reason), then all you need to do is replace one return .

The problem occurs with Modernizr / Geolocation and IE9 , it is actually a inheritance problem with IE9, not many Modernizr.

 return 'geolocation' in navigator 

instead:

 return !!navigator.geolocation // this causes the memory leak (silly IE9) 

https://github.com/Modernizr/Modernizr/issues/513

Take a look at this link, but basically the return statement for the Geolocation test needs to be changed, and this problem will be fixed!

+6
source

Source: https://habr.com/ru/post/915826/


All Articles