While testing Illyriad we found that over time the browsers IE7 and IE8 leak memory on Ajax calls using JQuery 1.4.
If you make a lot of ajax calls without changing page this can build up quite quickly and start causing issues. This is caused by the onreadystatechange event not being detached and IE not garbage-collecting the associated memory.
To fix this, locate these lines in the source JQuery file; already kindly annotated with “Stop memory leaks”:
// Stop memory leaks
if ( s.async ) {
xhr = null;
}
Add in these extra lines to change them to the following (we detach the abort event also for good measure):
// Stop memory leaks
if ( s.async ) {
try {
xhr.onreadystatechange = null;
xhr.abort = null;
} catch (ex) { };
xhr = null;
}
Don’t forget to minify your jquery file before including it. [We prefer using UglifyJS]
Also rename it slightly so users with cached versions pick up the new file
e.g. jquery-1.4.4a-min.js
No related posts.
Tags: ajax, browser, fix, ie, ie7, ie8, IE9, internet explorer, javascript, jquery, memory leak





August 22nd, 2011 at 6:24 pm
[...] coupled with the Fix for IE and JQuery 1.4 Ajax deal with most of the regular unexpected [...]