I <3 Steve McConnell*
Coding Horror
programming and human factors
by Jeff Atwood

March 13, 2006

Firefox Excessive Memory Usage

I like Firefox. I've even grown to like it slightly more than IE6, mostly because it has a far richer add-on ecosystem.

But I have one serious problem with Firefox:

Massive Firefox memory usage

This screenshot was taken after a few days of regular Firefox usage. That's over 900 megabytes of memory for a single, non-tabbed instance of Firefox.

What's going on? Well, according to my tests, Firefox never seems to release any of the memory it uses-- until you close all instances of Firefox. If you spend enough time browsing the web, and never close Firefox completely, you'll consume nearly a gigabyte of memory!

Because I often keep at least one browser window open for research or reminder purposes, this bites me a lot. I'll look at Task Manager and Firefox will regularly be gobbling up over 400 megabytes. This isn't uncommon. It's normal.

I don't ever recall having this problem with IE 6.

Of course, I can close all instances of Firefox and reduce memory usage back to zero, but why should I have to? I've read this techweb news article on the controversy around Firefox and memory usage, and I've implemented the workaround suggested in that article:

  1. Within Firefox, enter "about:config" (minus the quotation marks) in the address bar
  2. Scroll down to the entry "browser.sessionhistory.max_total_viewers" and double-click it.
  3. In "Enter integer value" field, type..
    • "0" to disable the cache
    • "1" through "8" to set the maximum cache as 1 through 8 previously-viewed pages
    • "-1" to return the cache to its default

Sadly, this fix did very little to address the problem. The above screenshot was taken after setting that value to 1!

Posted by Jeff Atwood    View blog reactions

 

« History of the OK Button In Praise of Good Design »

 

Comments

Jeff,

did you try the Firefox-safe-mode to see if any plugins you are using is causing trouble?

Take a look at
<a href="http://kb.mozillazine.org/Reducing_memory_usage_(Firefox)">http://kb.mozillazine.org/Reducing_memory_usage_(Firefox)</a>

They're also talking about some know memory leaks in Firefox
<a href="http://www.squarefree.com/2006/02/04/memory-leak-progress/">http://www.squarefree.com/2006/02/04/memory-leak-progress/</a>;

Thijs on March 13, 2006 03:34 AM

I have firefox (1.5) running near continuously and the memory footprint hovers around 100 meg. The plug-in theory is worth checking out.

Christian Mogensen on March 13, 2006 04:44 AM

I also cant't win the fight for memory with Firefox. The solution I use is Tab Mix Plus extension which has session saver and I restart FF in some intervels.

Papuass on March 13, 2006 04:59 AM

I filed a few bugs on memory consumption back in the day; back in the 1.0 era FF had gaping memory holes around images, and every 10 minutes browsing deviantart was another 100 megs used, even if it's mostly paged out after a while. 1.5 is much kinder on the ram, but still full of small leaks, especially images. I wish someone would run serious code coverage tools on it to diagnose and fix them, and simply make it impossible for extensions to use too much memory. (I've been guilty of making one that ate memory myself, once.)

It's nice to see that the problem is being addressed, at least, Thijs.

Foxyshadis on March 13, 2006 05:31 AM

I have found Firefox to be remarkably trouble free since I started using Opera as my main browser. I realise that Browsers are all about religion and not functionality but it does all the better-faster-lighter stuff just like people say it does and I only go back to Firefox now because the Web Developer Toolbar is great for live CSS editing.

Ben Moxon on March 13, 2006 07:01 AM

One thing that you can try is to add the key config.trim_on_minimize with a value of boolean true to about:config. This causes Firefox to release its working set when you minimize it. This usually allows me to minimize Firefox and restore it to take care of those times when it bloats uncontrollably.

Chris Lieb on March 13, 2006 08:43 AM

I've set browser.sessionhistory.max_total_viewers to zero, and browser.cache.memory.capacity to 65536 (not sure if it's related), and I haven't been seeing any of these memory issues.

Marc

Marc Bernard on March 13, 2006 08:57 AM

Why the high number of page faults? According to the task manager help, this is the number of times the process had to read information from the disk. Why would firefox be hitting the HD so much?

Coleman on March 13, 2006 09:36 AM

Coleman,

Probably because it's using 900 frickin' MB of RAM. Also,it keeps up to 8 pages cached in memory for each tab. That's the explanation given by the Firefox devs. It's not a bug, it's a feature!

I've got my sessionhistory set to 0, so it fetches each page fresh rather than hitting the cache. But I still return each Monday morning to work a find a "your virtual memory is low" warning dialog when I leave Firefox open.

Scott on March 13, 2006 10:00 AM

Scott,

8 pages cached per tab? Jeez. That should be configurable.

I added the browser.cache.memory.capacity and the config.trim_on_minimize keys to about:config. The config.trim_on_minimize seems to really help.

Overall, though, by looking at Peek Mem Usage and Mem Delta, FireFox appears to just be super memory intensive. At startup, it went to 25 MB of RAM and almost 9K page faults and 11 threads! That's for 1 tab, which is the Google home page. However, simply opening a new tab didn't consume any additional RAM. That only happened when I opened a page in the tab.

However, to be fair, those startup stats are almost identical to what IE6 does. IE6, though, automatically does the config.trim_on_minimize trick, though.

Coleman on March 13, 2006 10:55 AM

I'll third (fifth, ninth, whatever) the call to point the finger at plugins.

I have a situation where firefox is eating memory even when I don't do anything. Sometimes (and it's unfortunately not reproducable on demand) I'll leave firefox running with no loaded page and go home for the night. In the morning, I'll find that firefox memory usage has balooned to over 500MB. Without any user doing anything! (So obviously it's not the 8-cached-pages "feature" that the mozilla folks are talking about.)

But then, I did as people suggested and uninstalled all my plugins and over the course of two weeks, firefox memory usage behaved. I then put all my plugins back in and the problem resurfaced.

Now, I run over a dozen plugins so I haven't bothered to install them one at a time and try to find out which one is the problem. I just shut down firefox at the end of each day.

So, I think that the real bug report to file with mozilla is that they need to put in place some sort of limits and checks on plugin memory usage.

Bill Tomlinson on March 13, 2006 12:43 PM

Okay, I uninstalled all of my plugins. I had 3 installed; "Open in IE tab", "Extended Status Bar", and "XPath Checker". The only culprit I found to use unusual resources was the "Open in IE Tab", which apparently started 1 or more threads at startup. Firefox still uses up to 25 MB of RAM at startup, though.

Coleman on March 13, 2006 02:33 PM

Target system issues? I'm using 1.5.0.1 on Linux 2.6.15 with a few kernel patches, mostly revolving around latency reduction. Firefox, right now, has two tabs open on Gentoo's installation guides, one on Coding Horror, twenty one El Reg, two on Stallman's site (*) and, just for the Hell of it, I opened four random webcomics whose front pages are image-heavy to various extents. Firefox is currently chewing a something in the region of between sixty and eighty megabytes. Perhaps it's just that Mozilla's code monkeys are a lot more practiced at developing under Linux's memory models than Windows' one? Firefox on this Linux box does also leak memory while browsing, but at a much, much lower rate than the same version on Windows (on the same box, similar if not identical extensions installed).

(* Honest, I have a non-pathetic reason for visiting that site! Specifically, I'm looking for information on how to kidnap people with huge beards).

Richard on March 13, 2006 08:25 PM

> Target system issues?

You can find similar reports for Linux if you read through the original thread (just search for "Linux")

http://weblogs.mozillazine.org/ben/archives/009749.html

I suspect the people that haven't run into this tend to close their browser completely at least once a day or every other day.

If you leave at least once browser instance running, I guarantee you'll run into this after a few days of normal browsing. When I came into work today, Firefox.exe was using 400mb. This is pretty typical..

Jeff Atwood on March 13, 2006 08:43 PM

Geeze and the single biggest complaint that keeps me from running firefox long enough to find these sorts of problem are how long it takes to start up.

It astonishes me how long Firefox takes to startup. When I want to browse, I want to browse NOW. I open and close my windows constantly, and having that wait (albeit brief, but still longer than any other app I have except Delphi) injected EVERY time I start it up again is annoying and frustrating.

Maybe it's preallocating the 900mb of ram...

Xepol on March 14, 2006 01:22 AM

I'll be the second one to suggest Opera, a great browser which doesn't leak memory like celebrities leak home videos. Or Firefox. Not home videos, memory.

Opera might not have all the developer extension bells and whistles like Firefox does, but for actually browsing the web, it's awesome (plus, it tends to catch non-standards-compliant JS errors more than any Gecko browser does).

In fact, it makes me giggle when I see people installing yet more memory-leaking extensions to duplicate some of Opera's built-in functionality - *giggle*.


P.S. My Opera is currently using 67 MB of memory with 17 pages open.

Anonymous on March 14, 2006 02:18 AM

When I began to work with .NET I have been fooled by a very *high* memory consumption reported by task manager, using managed application.
I realize this happened *before* garbage collection. GC can be triggered by minimizing the application (Just try with Visual Studio for example).

When GC has occured, hundredfolds amount of memory are released.

This is not applicable to FF, but this gives a good example about how benefit garbage collection could be.

Anyway, I would be that a bug is causing this memory leak, rather than a design flaw.

Laurent B. (FR) on March 14, 2006 03:03 AM

Any chance it's actually Flash that's causing the problem? I saw the same thing and disabled flash.

Scott Hanselman on March 14, 2006 03:29 AM

Jeff,

Since you leave your browser open, enable the config.trim_on_minimize option in about:config. That way, when you minimize (you do minimize don't you?), Firefox will free memory. I'd be interested to see if in your case if Firefox will go back up to 400 MB used or whatever.

Coleman on March 14, 2006 09:24 AM

Jeff,

"Sadly, this fix did very little to address the problem. The above screenshot was taken after setting that value to 1!"

I tried setting it to one and still had some issues. Try setting it to 0. I did that and I haven't had seen mem usage over 250MB. It's the band-aid-on-a-sucking-chest-wound fix.

Scott on March 14, 2006 09:59 AM

Firefox on Windows is really bad, the Linux binaries don't seem to have problems like this, or at least not as terrible as the Windows versions.

H from H on March 14, 2006 10:18 AM

As I was reviewing the comments, I must have missed the answer to the original question Thijs put forth: "did you try the Firefox-safe-mode to see if any plugins you are using is causing trouble?"

Kyle A. Miller on March 14, 2006 10:29 AM

I am not having these problems at all on a Windows install at all.

What extensions are installed? With that amount of memory used, I would say there is a pretty good probability you are just using an extension that leaks memory. That "add-on ecosystem" has a downside. Start Firefox in safe mode and reproduce this, or figure out what leaky add-ins are causing this.

Maxx Daymon on March 15, 2006 03:37 AM

Some add-ons, such as AdBlocker, had known memory leaks that have already been fixed.

Open up your extenstions list and click the button labeled "Find Updates". Update every single extension if you can. I find that FF never gets the latest versions of any of my extensions, even though I told it to automatically check for updates.

Rick Scott on March 15, 2006 10:18 AM

Maybe the SAVE SESSION https://addons.mozilla.org/extensions/moreinfo.php?id=436&application=firefox
add-on will help.

Dominic Cronin on March 16, 2006 04:45 PM

There is a *much* better solution to Firefox: SeaMonkey.

Brief history: When firefox was pre-1.0 it was alawys assumed by the MoFo that all the old Mozilla devs would 'switch over' to Firefox when it became "stable"; that they were only 'maintaining' Mozilla 1.7 and perfecting Gecko (which firefox uses for rendering).

Well, after it went 1.0 the MoFo devs looked at the 50,000 known at the time (seriously) memleaks, lack of structured planning, lack of coding standards, etc. and went "what a piece of trash." Not a single MoFo dev stayed. Instead, over time they developed SeaMonkey which is now very very stable.

SeaMonkey has virtually every single feature of Firefox (including extensions and support for a great many Firefox extensions) but NONE OF THE DOWNSIDES. It is developed by the same people that develop the Gecko rendering engine and they are far more professional coders to boot. I know; I have reviewed both FF and SM codebases.

For more information, see my research study Firefox vs SeaMonkey vs Mozilla vs IE vs Opera (<a href="http://www.incendiary.ws/node/177).">http://www.incendiary.ws/node/177).</a> Since then, SeaMonkey has improved while Firefox has continued to leak.

HopeSeekr of xMule on March 22, 2006 12:23 PM

Hey Guys,

why is this???
When I go to this URL : about:cache?device=memory

Then I see some of the GIF images normally taking up 1Kb reserving a space of 250000 bytes

Key: http://www.domain.com/typo3/gfx/alt_topmenu_back_dummy.gif
Data size: 250000 bytes
Fetch count: 1
Last modified: 2006-04-26 21:10:52
Expires: 2006-04-28 15:46:41

Key: http://script.aculo.us/images/logo.gif
Data size: 313720 bytes
Fetch count: 15
Last modified: 2006-04-26 14:37:58
Expires: 2006-05-02 01:11:04

Why is the data size so huge?
Or are they counting the bits? :D

What could be the prob with that?

Ries

R. van Twisk on April 27, 2006 07:08 AM

setting the following to 0 seems to work well...

browser.sessionhistory.max_total_viewers

mine floats around 60mb with about 10 tabs open, most of them containing ajax/c-panel pages (constantly updating stats...)

the minimize function seems to help masses... knocks it down to around 50mb but then it creeps up again.

oh... anybody noticed that as soon as you open a java applet your mem jumps up by about 200mb???

DragoNero on September 30, 2007 02:29 PM

This type of thing has been happening with Firefox forever with me, whether I have add-ons or not (I think). I am surprised I've been putting up with it for that long, and I am getting motivated to find something else. I too have had to keep seeing the "Virtual Memory Low" warning from Windows, and I have 512 Meg here. More oddly, I very often find that even though all Firefox windows have been shut, a Firefox process is still shown running, often at rather high memory, in the Task Manager. My computer is whirring dealing with the memory, and as soon as I close that phantom Firefox process all returns to normal. IRRITATING.

SeaMonkey, as the other poster said, might be better based on his stats (though I thought it looked very like a return to 1999 Netscape-ville). I am now just trying out Opera. I'm already annoyed that they ignore Fitts Law and put the all important back button with an annoying 20 pixel or so border to the left of it so that you can't just mouse to the hard left of the screen and push the button--dumb!!

cm on April 21, 2008 09:59 PM







(hear it spoken)


(no HTML)




Content (c) 2008 Jeff Atwood. Logo image used with permission of the author. (c) 1993 Steven C. McConnell. All Rights Reserved.