It is no secret that Firefox can consume quite a bit of system memory during normal usage. While the number of tabs you have open and the installed add-ons certainly contribute, even a conservatively used out of the box installation can report quite a bit of memory usage.
This has caused a few Firefox add-ons to surface which claim to free up memory the browser no longer needs, but do they actually work?
A Two Minute Overview on How Windows Handles Memory
Before we dive into examining a memory cleaner, it is important to understand a little bit about the way Windows handles memory. This will be important so we can interpret the results of our experiment.
Don’t worry, we will cover this at a very high level so you don’t have to be a mega-geek to follow along.
As a quick disclaimer, this is an extremely brief summary of the very basics of Windows memory management. By no means should this be considered authoritative or definitive as it is only explained to level applicable to the subject matter of this article.
Windows is smart enough to know that unused physical memory is wasted memory, so it loads everything it needs and thinks it will need into memory. However, only what your system actually needs (both Windows and applications) and is actively using at the current time is reported as used physical memory. The rest (what Windows thinks it will need) resides in what is called virtual memory.
Virtual memory is essentially the data which is not actively required by the OS but is ready to be loaded into active memory at any time. You can very crudely calculate the amount of virtual memory your system has at any one time using this formula:
Virtual Memory = (Total Physical Memory – Used/Active Physical Memory) + Maximum System Page File Size
So, suppose you have a system with 4 GB of physical memory and a 6 GB maximum page file. You then boot up Windows and open a few applications (Outlook, Firefox, etc.) and Windows reports that 2.5 GB of physical memory is being used. This means you have 1.5 GB of “unused” physical memory and a 6 GB page file for a total of 7.5 GB of available virtual memory.
Remember, the OS is smart enough to know that unused physical memory is wasted memory, so it will fill the remaining 1.5 of physical memory with what it anticipates you will need so it can be accessed on demand almost instantaneously. This can be anything from minimized background program data to common OS functions.
So what happens when Windows runs out of physical memory to use as virtual memory? It writes this data to the system page file which is a huge (in our case 6 GB) file on your hard drive. While this allows for the OS to store pretty much any data it needs to keep in memory, writing and retrieving (aka a page fault) this information to/from the hard drive is orders of magnitude slower than accessing it from physical memory. This is why the more physical memory you have the faster your system can run. The less your system uses its page file, the faster it will perform.
Monitoring Firefox’s Memory Usage
For our investigation we will simply be using Windows Task Manager. We will be tracking the following columns (the descriptions are defined on Microsoft’s page):
- Working Set = Amount of memory in the private working set plus the amount of memory the process is using that can be shared by other processes.
- Peak Working Set = Maximum amount of working set memory used by the process.
- Memory (Private Working Set) = Subset of working set that specifically describes the amount of memory a process is using that cannot be shared by other processes.
- Commit Size = Amount of virtual memory that is reserved for use by a process.
We will be using an out of the box installation of Firefox 4.0.1 with only the Memory Fox add-on loaded. In Firefox, we will have the following tabs open and will not do anything other than scroll up and down the loaded pages.
After waiting a few moments for everything to finish loading, Windows Task Manager reports the following for Firefox.
Now when we start the Memory Fox add-on, look at the dramatic drop in the amount of reported memory use.
Also take note that a new process is started by this add-on which is what handles the memory functions.
Leaving Firefox idle and watching the Working Set and Memory values, you can see there is a constant struggle between Firefox needing active physical memory and the memory cleaner add-on reclaiming this memory.
Here is the reported memory usage taken every few seconds while Firefox is left idle.
Note the drop in the Working Set and Memory values. This the is memory cleaner reclaiming the system memory.
After going up for a bit, you can see another drop.
Lather. Rinse. Repeat.
Additionally, if you do nothing but switch tabs and scroll up and down the loaded pages, you can see the numbers fluctuate a bit more drastically which will be explained below.
Interpreting the Results
When you first look it, you would think, hey this is working great. But take a look at the Commit Size column and you can see that this value never really changes. In fact is goes up once you start the memory cleaning add-on.
Remember, the Commit Size column reports the actual amount of memory (physical + virtual) Windows needs to run the respective application. So in our example, the ~120 MB is reserved and active on the system specifically for Firefox and is residing in either unused physical memory and/or the system page file. Also remember that if the page file needs to be used, there is a noticeable performance impact because the virtual memory has to be written to and read from the hard disk which is significantly slower than physical memory.
So essentially the memory cleaner is moving active physical memory to virtual memory (because the memory is reclaims has to go somewhere). When this happens, Firefox no longer has the memory it needs to function actively available so it has to ask Windows to move the respective data it needs from virtual memory back to physical memory. And around and round we go…
At best, this process does nothing useful at all and at worst it causes a massive amount of unneeded page faults because, again, if Windows has to bring the page file into play then there is going to a noticeable performance hit. This can especially be the case on system which do not have much physical memory (where pretty much all virtual memory is kept in a page file), which is ironic because these are the systems a memory cleaner was “designed” for.
The moral of this whole story is quite simply, memory cleaners do nothing but shift around numbers. Any OS is going to know how to handle memory appropriately, so just let them do their thing.
Managing Firefox’s Memory Usage
Since we have shown that memory cleaning add-ons do not really do anything useful, what can you do about the large amount of memory Firefox uses? Here are a few suggestions:
- Remove add-ons you don’t need (especially any memory cleaning ones).
- Keep the number of tabs you have open to a minimum.
- Periodically close Firefox and relaunch it.
- Add more memory to your system.
- Don’t worry about it.