Leak Patterns


The information published in this post is now out-of-date and one or more links are invalid.

—IEBlog Editor, 21 August 2012

Justin Rogers one of our developers, just posted an article on MSDN where he discusses memory leaks with Internet Explorer. This article helps developers by explaining the issues and some best practices to fix web pages that leak memory. This includes such different types of memory leaks including circular references, closures, cross-page leaks and pseudo-leaks. The issue of memory leaks in IE has been the topic of recent discussion elsewhere and while we hope to improve in this area in future versions, this article should help developers today.

Thanks,
-Dave

Comments (40)

  1. Anonymous says:

    It would be nice if in the IE 7 there would be a method of catching those errors somehow… In the current IE I had gotten a msg that a page is using up memory and its better to stop execution of the scripts on it… but better protection would definitely be nice

  2. Anonymous says:

    Fix web pages that leak memory in IE? How about fixing the bloody browser so that it doesn’t have memory leaks in the first place?

    In other news, the Office team gives hints how to fix one’s Word documents to prevent crashes of the application. Microsoft is one funny company…

  3. Anonymous says:

    I just don’t care about the previous comment, because "everything that goes across a narrow spirit always take its dimension" (sorry for the translation from French :o)

    Now, just a note : why does the browser has to take care of bad pages ? Why don’t we just say : this page is too ugly, don’t show it, and learn HTML/DHTML before everything ?

    So, IMHO, the only thing to do is to check if a memory leak is to come (set a max memory limit for one page), and just run an alert such as the current "This script is running IE slow, should we stop it ?" alert for bad Javascripts, and that all.

    Adding many controls in For/while statements would only do one thing : slow IE for all scripts, including the good ones.

  4. Anonymous says:

    "So, IMHO, the only thing to do is to check if a memory leak is to come (set a max memory limit for one page), and just run an alert such as the current "This script is running IE slow, should we stop it ?" alert for bad Javascripts, and that all."

    Firefox already has this…

  5. Anonymous says:

    The article from Justin Rogers is great, but all figures in it are terribly scaled and almost not readable. Why can the browser not release all leaking objects when the user navigates away from the originating web page?

    BTW another very annoying bug in IE is that the user cannot always stop the navigation (download process) by pressing the stop button.

  6. Anonymous says:

    Why *I* should fix *your* bugs?

  7. Anonymous says:

    "why does the browser has to take care of bad pages ? Why don’t we just say : this page is too ugly, don’t show it, and learn HTML/DHTML before everything ?"

    Because you can write perfectly valid DHTML code and IE6 still leaks like a sieve. You need to add hacks to make it work properly (like crawling through every object on unload to null everything). What’s the point of the garbage collecter if you have to manage memory yourself.

  8. Anonymous says:

    Quote: "Firefox already has this…"

    Can you back this up with proof?

    Please don’t claim something if you don’t back it up at the same time.

  9. Anonymous says:

    Please don’t post a comment if you don’t have anything interesting to comment.

  10. Anonymous says:

    With the leak patterns so well understood, surely the IE team should have patched these problems, thereby preventing the issue.

  11. Anonymous says:

    I suspect this entry will get flooded with users of a lesser mental capacity that will forget that IE executes code (ActiveX and Javascript) so it must deal with poor code in these languages.

    Although considering that the people behind this blog are well aware of it’s energetic userbase, they could have worded this post a little better so as not to confuse IE’s internal memory leaks, and leaks caused by parsing HTML/XML/JS/CSS/ActiveX/ETC

  12. Anonymous says:

    Seriously. If other browsers can handle this for us, so should IE.

    Javascript is a garbage-collecting language and HTML is a document markup language. There is no way an HTML/Javascript developer should be expected to do memory management.

  13. Anonymous says:

    Good article though. Very informative and easy to understand.

  14. Anonymous says:

    I for one am sick and tired of working around 10-year-old bugs and crippled functionality in your broken software.

    From now on I’m just going to redirect IE users to an "upgrade your browser" splash page and serve up all my content in XHTML 1.1 with the correct mimetype.

  15. Anonymous says:

    kL: do you understand what it’s here about? I bet you don’t. It’s not about IE leaks but about excesive memory usage in JS. If you spoil your JS script, you fix it. Comprende?

  16. Anonymous says:

    > Now, just a note : why does the browser has to take

    > care of bad pages ? Why don’t we just say : this

    > page is too ugly, don’t show it, and learn HTML/DHTML

    > before everything ?

    Because Javascript and DHTML, by design, can only lead to leakage. See JGWebber’s blog (http://jgwebber.blogspot.com/2005/01/dhtml-leaks-like-sieve.html) for more informations.

    From the same JGWebber, i’d also wish to point Drip (http://jgwebber.blogspot.com/2005/05/drip-ie-leak-detector.html), a wonderful IE leak detector and a quite fine tool, and as another leak-busting ressource you can check Novemberborn’s Event Cache (http://novemberborn.net/javascript/event-cache)

    Looks like IE devs check the web development blogosphere, since IE’s leakages have been quite an extensive subject for the past few weeks… shame they didn’t link to blogged resources on top of the new MSDN article, though.

  17. Anonymous says:

    I have noticed IE pick up the odd circular script and offer to shut it down, and certainly there’s less leaks than there used to be a few years ago. All good.

    One thing I’d like to see in IE7, purely for development reasons, is the ability to ‘stop’ script instantly with a keypress. I can’t be the only person who’s accidentally popped up a thousand alerts while debugging a recursive loop, and had to close the browser through task manager because they’re modal. It’d have to stop existing timeouts, submits, navigates too. Just F12, bam, stopped dead, so I can examine the state of the page.

  18. Anonymous says:

    That first image in the article is completely illegible. Suggest you up the dimensions a bit, or bold the lines and text, so we can see what is going on.

  19. Anonymous says:

    Ya know, I’m ususally the first to point out the illogical nature of microsoft’s actions, but to all of those pointing to IE as a sieve, keep in mind that Firefox has a GIANT memory leak as well. (although I’m told it’s fixed in 1.1)

    Clearly, IE isn’t alone in this, however one wonders why it’s taken so long to correct.

  20. Anonymous says:

    I think that the biggest problem in IE is that when you put a lot of memory, IE goes slow and slow. FireFox don´t do that. Run the test below:

    <script type="text/javascript">

    var globalArr = new Array();

    for (var iter = 0; iter < 10; iter++) {

    var d1 = new Date();

    for (var i = 0; i < 10000; i++) {

    var blah = "string";

    }

    var d2 = new Date();

    for (var k = 0; k < 10000; k++)

    globalArr.push("a string");

    alert("Iteration [ "+iter+" ] globalArr count "+globalArr.length+" Time: "+ (d2.getTime() – d1.getTime()));

    }

    </script>

    Anyone have some good news about that!?

    Thanks!

    Thyago Liberalli

    thyago@gmail.com

  21. Anonymous says:

    Why isn’t this blog listed under ‘IE Blogs’ on the left?

    And while we’re at it why can’t I aggregate all those blogs so I get a single RSS feed?

    planetplanet.org is excellent for this, of course it’s uninnovative Free Software so you guys can’t use it, but surely there’s a EULA-heavy alternative?

  22. Anonymous says:

    Quote: "Firefox already has this…"

    Can you back this up with proof?

    Please don’t claim something if you don’t back it up at the same time.

    —————————————

    It has a function where if a script causes Firefox to perform slowly, it’ll ask you if you want to abort it. I find it quite useful.

  23. Anonymous says:

    btw the rss feed is busted again.

  24. Anonymous says:

    I second the call for an IE Bloggers aggregator.

  25. Anonymous says:

    Yes, Firefox definitely ask the user to abort "locked up" scripts. Write one yourself and try, and you’ll get your proof. 🙂

    Regarding memory leaks, that’s another matter and something I’ve found Firefox to have problems with before, especially after browsing image heavy sites like deviantart.com, but I think it has improved somewhat in the Firefox 1.1 builds. They also closed a long standing bug regarding this.

  26. Anonymous says:

    Please keep in mind that Firefox is still in it’s early stages, so it’s only natural that it will have more bugs. I do wonder however, why some nasty quirks still exist in ie.

  27. Anonymous says:

    yes, firefox has poor behaviour with images. Especially large ones on old computers. However, the way it deals with javascript is quite delightful. About the only thing I’ve found that causes a significant amount of trouble is something like:

    while(1){alert("I am being a pain");}

    but of course this is not firefox’s fault.

  28. Anonymous says:

    Please fix the closure problem, http://www.FreeTextBox.com gives me gray hairs over this!

  29. themuuj@gmail.com says:

    Alan Trick:

    IE could take a stance and fix that, if they felt so inclined.

    All it takes is a button somewhere to stop a javascript from executing, even when a modal dialog is present (maybe put it on the title-bar of the dialog?).

    There are times when Javascript can lock up IE. I personally don’t think script should execute at Normal thread priority, but it may be difficult to run a script in its own thread without harming performance with extra synchronization locks. Executing a Sleep automatically every so often in a script might also help, but this would also hinder script performance for those who do not abuse the system.

    Anyway, Javascript shouldn’t be able to eat up your CPU resources or keep you from using your browser.

    The alert problem, if nothing else, needs a solution.

    Another solution might be that after the 3rd or so consecutive alert in a script, provide an extra button that basically means "Go away you pesty script!"

  30. Anonymous says:

    MS have hundreds if not thousand of programmers not mentioning outsourcing and cannot develop a better web browser ? If js / jscript make the leak IE should know how to handle it. If IE itself leak then IE should know how to handle it. Isn’t that what these programmers hired for ?….Providing better solution/eXPerience for the worldwide market.

    My web based IDE sux because of this things, luckily IE come with the OS. If I should pay for IE….

  31. Anonymous says:

    Welcome to The Desert Skies Podcast episode 13.  We were going to have a book review of a book on the…

  32. Anonymous says:

    Welcome to The Desert Skies Podcast episode 13.  We were going to have a book review of a book on the…

  33. Anonymous says:

    how to get a high school diploma online for free