January 15th, 2007

  Firefox2 + GMail == Memory Leak


Just noting that I closed my ‘gmail’ window, and my Firefox process went from 883M to 585M.
I guarantee that 300M weren’t being used by the gmail page as it stood. Perhaps Google’s Javascript foo is not as powerful as they’d like, and it’s holding onto old AJAX results?

I can guess a few other things about what might be going wrong (caching AJAX requests in the browser, for instance), but one way or another, if you have memory problems with Firefox 2 and you keep a gmail tab open, try closing your gmail tab now and then.

I have to wonder if it’s a general AJAXy problem with Firefox, or specific to gmail…

One way to test (which I’m going to try soon) is to try a ‘reload page’ instead of a ‘close tab’, to see if it’s the browser/page-renderer/caching keeping the memory occupied, or the JavaScript on the page that is abusing memory.

There are limits to how much CPU we allow any given page of JavaScript to have; I’m surprised there aren’t any limits to how much memory it can have.

— Morgan Schweers, CyberFOX!


  1. On Kal Says:

    “I have to wonder if it’s a general AJAXy problem with Firefox, or specific to gmail…” – I believe that there is nothing inherently wrong with AJAX in Firefox. To begin with, AJAX is not some kind of magical JavaScript module in Firefox (or any other browser, for that matter). It all depends on the implementation. *MAYBE* it has to do with the implementation of XmlHttpRequest in the JavaScript engine of Firefox. Memory leak is a problem that can occur with any looping or recursive JavaScript fragment that doesn’t release reserved memory when it should.

  2. On Cyberfox Says:

    You’re right; I had a specific potential issue in mind, where Firefox2 might be in-memory caching the results of XmlHttpRequest ‘pages’, and somehow bypassing the limits on them. It’s frustrating that my Firefox2 regularly grows to 750M+.

    In general, if I find that my browser has gotten unreasonably slow, I can close my gmail tab, and it works better. I don’t like closing gmail, but it might be for the better; I occasionally get more done without it up. 🙂

    Anyhow, you’re right, I wasn’t specific about the kind of problems I thought of when I said, ‘general AJAXy problem’. I was focusing on the ‘AX’ part.

    It’s also been pointed out that there’s a decent chance it’s a bad interaction between one of my plugins and gmail. I have no way to reasonably test that, but that I agree is possible.

    — Morgan Schweers, CyberFOX!

  3. On Kal Says:

    It turns out that it may not be just Gmail. In fact, Firefox “leaks” memory almost all the time, the reason being that Firefox almost never releases memory back to the operating system on its own accord. Instead, it usually keeps “released” memory in its heap, and only gives memory back to the operating system upon request. This page explains a lot: http://plugindoc.mozdev.org/faqs/memusage.html

    There is a way to force Firefox to shrink its heap, but it apparently only works on Windows, and I can confirm that it does work on Windows because I just tried it: http://www.solo-technology.com/blog/2005/12/23/quick-firefox-tweak-free-mem/