Novemberborn, Straight lines circle sometime

Memory Leaks: Gone!

At Xopus we develop a pretty big (~50k lines) JavaScript application to edit XML documents through a WYSIWYG interface. With such a large application there’s a large risk of memory leaks. Indeed, this is what we’ve been experiencing in Internet Explorer 6. We’ve also seen a decrease in performance as memory usage increased. These leaks, however, do not occur in Internet Explorer 7. And, as of just 10 days ago, they no longer occur in IE6 on Windows XP.

On June 12th, Microsoft released security update MS07-033. Included in this update is the following:

General distribution release (GDR) fixes
A memory leak occurs in Internet Explorer 6 when you view a Web page that uses JScript scripting on a Windows XP-based computer (KB929874)

And indeed, IE 6 on Windows XP no longer leaks memory, nor performance. This is great news for all JavaScript hackers, there’s no need to worry about memory leaks anymore!

The one cave-at is that this fix is only available for Windows XP. For Xopus this means we’ll still have to fix the leaks, since some of our clients are still running Windows 2000. Users who haven’t installed the latest security updates will also experience memory leaks in IE 6. In the end though, Microsoft fixed the memory leak issues in Internet Explorer, and I’m thankful for that.

link | javascript | 22 June 2007, 16:06


Comments

  1. hurray!

    ed | 22 June 2007, 20:26 | link

  2. They only way to detect a patched version of IE6 on XP is to look for “SV1” in the userAgent string. Even then you can’t be sure you have the latest patch. This is still good news though. :-)

    Dean Edwards | 24 June 2007, 21:21 | link

  3. That sound great! Let’s just hope that no new bugs pop up ….

    Kevinin | 25 June 2007, 12:45 | link

  4. Yeah, this really doesn’t change anything for developers.

    This is great for those 5 IE6 users on XPSP2 that regularly update but have manually NOT updated to IE7 (it’s a forced upgrade you’ll remember).

    Unfortunately, we really can’t give up patching our memory leaks.

    Actually, this could be really really bad for developers. If you setup a testing box with IE6 to test your app and you accidentally get the latest patched version, you’ll be blissfully unaware of all the memory leaks that your site has for the majority of IE6 users. Awesome!

    Thomas Aylott | 26 June 2007, 14:33 | link

  5. Does this fix work with Windows Server 2003?

    Nicu | 27 June 2007, 09:06 | link

  6. No it’s just Windows XP I’m afraid.

    Mark Wubben | 27 June 2007, 10:36 | link

  7. I can see Thomas’ point, but still, Microsoft fixing bugs must be a good thing, surly!

    patrick | 27 June 2007, 17:34 | link

  8. All XP users who keep their software updated will get this patch. Those who don’t will likely have other issues with their machine, browsers leaking memory won’t be causing it to run slower.

    Mark Wubben | 27 June 2007, 18:54 | link

  9. To be honest i cant see any diff since this patch, the only thing I’ve find out is that IE releases the leaked memory when minimized. So what can I say to my users, minimize IE window every 4 hours?

    Michal | 13 July 2007, 10:33 | link

  10. I’m definitely experiencing memory leaks in IE7 that releases substantially when I minimize IE. I don’t know how to fix it. I don’t remember it always doing this. :(

    Alocasia | 25 July 2007, 05:58 | link

  11. Yes same as above, having memory leaks that are released when refreshed.

    It gets to the point with alot of tabs etc open that i actually loose Copy & Paste, but regain it if i minimise or close a tab to release some memory.

    Slightly annoying. Anyone else loosing Copy & Paste ability at times?

    Taree Internet | 27 July 2007, 17:32 | link

  12. Does this fix apply for IE7 as well? I installed all automatic updates but the leak still occurs. Then I spent one hour trying to search the pathetic update sites and documentation that m$ put together, hoping to manually identify and download the patch, but I couldn’t find one…

    Does this mean that IE7 users are out of luck?

    Mihai Bazon | 9 October 2007, 13:48 | link

  13. The fix described in this post is in fact a clean-up method which clears leaks from nodes still attached to the document when a page is unloaded. So leak patterns are still possible.

    Mark Wubben | 9 October 2007, 18:14 | link

  14. I think it’s pretty good news, even if it’s really hard to control, memory leaks should not be in such important softwares like IE. The software we used at my last job was relying on IE and we had to reboot a pretty important computer 3-4 times a week because of these leaks.

    Jeff Waren | 16 November 2007, 04:38 | link

  15. I’ll agree with a poster a few above me. I have been losing copy and paste ability as well. Nice to know I’m not alone… I guess. When I have too many tbs open, it gets bad. Sometimes 10 is too many. Sometimes just 5 or 6. Very strange indeed.

    George T. | 20 February 2008, 05:52 | link

  16. Glad to hear there are no more memory leaks in IE6, because I had some serious problems with that in the past.

    Marc Hernandez | 23 February 2008, 21:08 | link

  17. Currently, if i open a lot of browser about 10-15, i will lose the ability to copy and paste. Few times, i got my pc automatically shutdown due to memory leak.

    James Burt | 27 February 2008, 15:50 | link

  18. Thanks to Mark for reopening comments on this post so that I can post a couple of tips here.

    Those of you who are only able to open a certain number of windows, and those of you who lose copy and paste, your problems might not be caused by a memory leak. The problem might be caused by exhausting the desktop heap. I don’t need to write much about this because you can google the term SharedSection and find thousands of posts about it.

    Microsoft basically made a misjudgement when they set the default value for this which I believe is either 3 or 4 mb. Most of the stuff you read on the web recommend increasing it slightly to maybe 6 mb or so, but if you have 1 GB or more RAM you should increase this to a more realistic 20 MB. I think that actually 12 mb will proably suffice, but I say why ever bump against that limit again. If you have windows vista 64 bit, I believe the default is 20 MB.

    When you run out of desktop heap (sharedSection) you lose the ability to copy and paste, you can’t open new windows, and sometimes really weird things happen on the screen where it seems like windows is toggling through every open window many times. Usually copy and paste is the first one to go.

    The sharedsection is in a long string and it is a string of three numbers, something like 1024, 4096, 512. You want to increase the 4096 to a larger number.

    In addition there is a systemwide buffer (address space) that is 48 mb. When you increase sharedsection, you should increase this buffer as well. I usually increase it to 80 mb on the systems that I use, again assuming that you have 1 GB or more RAM. The name of this parameter is SessionViewSize.

    If you don’t know how to make these changes then you should go to google to learn how to edit the registry.

    While you’re tweaking things, you should go ahead and increase GDIProcessHandleQuota to 65000 (windows XP and above. A lot of sites incorrectly state that the limit for GDIProcessHandleQuota is 16384. According to the microsoft site, that was the limit for windows 2000, but the limit for XP and above is 65,536.

    Go ahead and set USERProcessHandleQuota to 16000 while you’re in the registry. The limit for this field is 18000, but I’ve read on a microsoft site that the system could become unstable if you use over 16000. I do not know if that is current info or not, or if it applies to vista or not, but just to be safe I don’t go over 16000.

    When setting these registry values, remember to select decimal not hex notation.

    If you implement these suggestions on a machine that has enough ram you should be able to open at least 10 windows of 20 tabs each in internet explorer.

    I have a few other tips, but to keep this post from being crazy long, I’m going to do that as a separate post.

    Greenville IT Support | 25 November 2008, 09:09 | link

  19. There are other limits on the number of Internet Explorer open windows. Everything here assumes you have at least 1 GB or RAM.

    Assuming that you took the steps that I outlined in my previous post then you have gotten rid of the system limitations on the number of open windows. Internet Explorer will limit you in other ways, including memory leaks and handle leaks. First I will describe some of the things that cause problems, then I will mention a couple of fixes. Unfortunately, the fixes aren’t that good.

    First, if you’ve got a lot of RAM and you made the changes you should really be able to open 200 - 400 or more tabs spread across multiple windows. As time goes on from the reboot and you open and close windows then the limit goes down.

    First it’s important to distinguish between two copies of Internet Explorer running, and two IE windows open. If you click on the IE shortcut twice from the desktop, you have two separate copies of Internet Explorer running. If you click on the IE shortcut once, then go to that window and click on File - New Window, or right click on something and click on open in new window, then you have two windows open, but it’s only one copy of IE. Task manager can help you see this.

    Any given instance of IE seems to crap out somewhere between 500 - 800 mb. This could translate into between 20 - 200 + tabs depending on the complexity of each each window that you have open. Once you reach this magical limit, IE will just suddenly lock up, with no chance to fix it.

    Here’s a fun little test. Open IE, go to google, then open task manager, and note how much memory is being used. Don’t do anything else in the google window. Now in that same instance of IE open several tabs to some complex sites, and actually navigate around in those sites for several hours. Now close all the tabs except for the original google tab, then go to task manager. What has happened. Your original copy of IE that started out using 30 MB is now using 90 MB. This can happen with any version of IE, and is really not a bug in IE, even though it seems like it. Discussion of why that is, is best left for another venue.

    When you close that copy of IE you get back most, but not all of that RAM. In fact, I’ve seen my system have over 500 MB of leaked RAM after a few weeks of being in and out of IE without rebooting.

    Here’s what you can do to help some if you tend to have lots of open windows (all of these assume the proper version of IE):

    1) The most important thing is to have multiple instances of IE open. Don’t open an instance for every window you want to have open, but try to generally limit yourself to 20 or 30 tabs per instance of IE. If the window has been open a long time then reduce those numbers.

    2) If you have a window that you have a lot of open tabs in, and you’ve worked in the window for several hours or days, then you can close the window and tell it to reopen these tabs the next time you open IE, then reopen IE. That way you get a fresh start on part of the memory leaks.

    3) From time to time look in task manager and see if any window is starting to use over 400 mb. If so, it’s time to do something so that you don’t crash the window. Close some tabs, or close and reopen the window as mentioned above.

    4) If you have a window that has a lot of tabs and it represents lots of work to get there, you can set a bookmark by using the add tab group to favorites command. Of course this loses the window history, but at least would allow you to go back to all your open windows.

    5) Where possible, try to reboot your system every few weeks.

    Some of these problems can manifest in other applications besides IE, but they tend to happen more often in IE and be more visible.

    I personally have some windows that I’ve had open for as long as a few months with a dozen or more tabs open, and I typically have over 100 tabs open spread across several windows. It’s not unusual for me to have 200 tabs open.

    By taking the steps outlined in my previous post and this one, you can really expand your use of windows and tabs. Now all you have to do is to find a good reason to have that many open at once.

    Greenville IT Support | 25 November 2008, 10:20 | link

Leave your comment

Please keep it polite and on topic. Yes, your e-mail address is required, but it's kept private. HTML is not allowed in the comments but you can use Markdown. Non-contributing comments run the risk of being removed. Especially if the website seem “fishy”. Spammers, beware.

(required)
(required, kept private)
(optional, but let's share it!)
(required)

Remember my details


Novemberborn: Extra

About the author

Mark Wubben is a European Dutchman and web hacker, based in Copenhagen, Denmark. Supercollider is Mark's freelance alter-ego.

Read more about Mark...

Go to

Jobs (NL)

Xopus zoekt programmeurs! Verbeter de code en win!

Subscribe