Monday, October 8, 2007

How to fix the Firefox memory leak

For most users, Firefox doesn't use an abnormally large amount of memory. For others, however, Firefox's memory consumption is a major problem. Typical Firefox memory usage reported by Linux is around 50-100 MB, with virtual memory usage at 100-150 MB. These numbers will vary because Firefox is configured by default to use more memory on systems that have more memory available and less on systems with less.

Firefox memory leak? It doesn’t have one. Unfortunately, because of the way it’s configured to run out of the box it *looks* like it has one.

Follow these simple steps to get your Firefox memory usage under control.

These configuration changes are a trade-off between internet browsing speed and memory usage. They are most useful if you are multitasking and need Firefox to be less of a memory hog while using other applications.

#1: about:config

Type “about:config” into your address bar to access the hidden configuration options for Firefox.


#2: browser.cache.memory.capacity

Controls how much memory is used to cache pages.

Right click on the page and choose New then Integer and create an integer called browser.cache.memory.capacity and set it to a low number. This controls how many kilobytes of memory are used for the browser’s cache.

NOTE: number in screenshot is too small. Aim for 80% of whatever the default is.


#3: browser.cache.disk.capacity

Controls how much disk space is used to cache pages in kilobytes.

Set browser.cache.disk.capacity to between 5000 or 15000.

128MB to 512M -> 5000.
512BM to 1GB of RAM -> use 15000


#4: config.trim_on_minimize (optional)

Configure Firefox to swap memory to disk when minimized. This will make Firefox less responsive if you minimize/maximize a lot, but it is good if you need to free memory while multi-tasking to other applications.

Right click on the page and choose New then Boolean and create a boolean called config.trim_on_minimize and set it to true. Now when you minimize the window it will free up memory.


#5: network.prefetch-next

Network link prefetch will download all pages with the rel=”prefetch” tag. This uses up more memory than you would otherwise think.

Set network.prefetch-next to false.


#6: browser.sessionhistory.max_total_viewers

This controls how many pages of history are kept in the back/forward buttons. Lower the value to something acceptable. If you do not use back/forward often then you can set this very low.
Set browser.sessionhistory.max_total_viewers to a low number.


Once you've done this you should notice a speed improvement on your PC when
using Firefox.

Linux check memory usage:

Linux comes with different command to check memory usage. free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.

vmstat command reports information about processes, memory, paging, block IO, traps, and cpu activity.

Then you can use top command which provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.

free command

Display free memory size in MB:

$ free -m


             total       used       free     shared    buffers     cached
Mem: 750 625 125 0 35 335
-/+ buffers/cache: 254 496
Swap: 956 0 956
Displays a line containing the totals memory in MB:

$ free -t -m


       total       used       free     shared    buffers     cached
Mem: 750 625 125 0 35 335
-/+ buffers/cache: 253 496
Swap: 956 0 956
Total: 1707 625 1082

vmstat command

Type vmstat command at shell prompt:

$ vmstat


procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 0 131620 35432 341496 0 0 42 82 737 1364 15 3 81 1

top command

Type top command at shell prompt:

$ top

To exit from top command type q key.

Read man page of free, vmstat, top command for complete information.


Eric D said...

Another option would be to use the Opera browser. That will solve all the memory issues. :)

Rakesh Kumar said...

Opera got great memory usage yet but I prefer Firefox because of the customizability (everything Opera can do , FF can too - and I can add and remove features at will) and the memory/CPU usage is a red herring if you keep your profiles neat and tidy and your extensions updated. But I do like Opera's out of the box configuration, and would love to recommend it to people who don't want to configure FF, but so many sites just don't like it. That's the way things are, so Firefox is really the only option at the time being. :)

Anonymous said...

I use a new browser called Enigma. You can obtain it for free at
You can find the link to obtain it just above the products section.

Enigma runs faster than Firefox and does not take up too much memeory like Firefox, Opera, or Safari. I have 35 windows open right now and it runs fast.