Garbage Collection improvements in Firefox improve memory usage

Martin Brinkmann
Jul 10, 2015

Mozilla introduced Garbage Collection in Firefox 38 that improves memory management of the web browser as part of the organization's ongoing effort to bring memory usage of the browser down and optimize it as best as possible for all use cases.

Compacting is one feature of the garbage collector that is currently only supporting JavaScript objects. It dropped memory usage on a test system -- the lead developers own - with 50 tabs open by about 2%. While that may not look like much, as it dropped usage on the system by about 30 Megabyte only to 1300 Megabyte total, it is just the first step with others to follow which will bring down memory usage further.

So how does compacting work in Firefox?

The JavaScript Heap uses arenas, 4K blocks of memory which are made up of cells that have fixed sizes. Each arena contains cells of the same kind and size only, and can only be freed if there are not any live cells in it anymore.

Memory problems arise when many arenas with few live cells each exist as the space cannot be released to memory in this case, While "dead" cell space can be used by the same kind, they cannot be used by different kinds.

Mozilla's algorithm works by moving live cells between arenas to reduce the number of arenas used by the Heap. It works by selecting appropriate cells, moving them and updating all pointers to make sure no objects or data is lost in the process.

The selection process lists all arenas with live cells in decreasing order and splits it in half to move cells out of arenas with few cells to release them to memory afterwards.

It is interesting to note that compacting triggers only on three specific events currently:

  1. When Firefox is running out of memory.
  2. When the operating system sends a "memory pressure" event.
  3. When the user has been inactive for a certain period of time (currently about 20 seconds)

Check how much memory free cells use

You can check how much memory cells use in Firefox.

  1. Type about:memory in the browser's address bar and hit enter.
  2. Search for js-main-runtime-gc-heap-committed
  3. Locate gc-things in its tree.

Additional information about the process are available on Mozilla Hacks.

Closing Words

There is a imbalance currently in the reporting that covers Firefox and Mozilla. Feature removals and additions get lots of publicity, usually by Firefox users opposing the change, whereas core improvements like these, that are mostly under the hood, get little to no publicity at all.

Mozilla could do a better job at promoting those under the hood improvements as those are features that are -- usually - welcome by all users of the browser.

Now read: Which Firefox features would you like to see removed, and which polished?

Garbage Collection improvements in Firefox improve memory usage
Article Name
Garbage Collection improvements in Firefox improve memory usage
Mozilla introduced Garbage Collection in Firefox 38, and one of the features allows for the compacting of data to save memory.

Tutorials & Tips

Previous Post: «
Next Post: «


  1. nekosan0 said on August 29, 2015 at 12:21 pm

    I often have troubles with new firefox
    after updating v38. And now 40.0.3, too.

    The thing happened:

    (1)firefox goes into petit-freze very often.
    (about 10 second a time)
    when it happened, all firefox pages are freezed.

    (2)firefox-icons on task-bar(windows7)
    are shuffled suddenly.

    (1)… it seems happen when firefox need
    to allocate much memories.

    example: opening a new heavy page
    which has many pictures, flash-objects…

    ajax gets pictures (ex: scrolling google map
    watching video files)

    (2)… it seems hapen when firefox returns from petit-freeze
    it causes focus-shuffle ,too.
    focused window disappears to back window ,
    not focused window appears to front window.
    so I lost the window which now I’m reading.

    (by the way, I always open as a new window each web-site
    substitute for a new tab.)

    I guess that:

    (1) the garbage collection algorithm is changed at v38.
    (2) when firefox needs much memory ,
    firefox uses the new garbage collection.
    (3) the garbage collection causes aka “stop-the-world”
    with every windows every tasks of firefox.
    and it seems as “petit-freeze”.
    (4) and the garbage collection causes…
    restart some tasks or windows of firefox.
    and “Windows-OS” may recognise that
    the old-tasks are terminated
    the restarted-tasks are apeared as new windows,
    so new windows are appears on right-side of task-bar.

    I wonder what and how garbage collection logic is changed.

    I know that new logic is “Generational Garbage Collection” ,
    which has better memory efficiency than old logic.
    and how the logic is processed….like JavaVM.

    But I didn’t think that the treatment for objects(variable,
    arrays, strings, instances…) is not changed each logic.

    A garbage collection logic does :
    unyoking(flashing) disused memories for re-usable
    coping and re-alligning objects into another memory

    “Generational Garbage Collection” does it ,too.
    (but the logic has some differences how to use of memory.
    classifying objects as older or younger
    so it is called “Generational…”)

    I think each logic is same about memory-copy-process.

    If the treat of memory has had changed,
    it can cause these phenomenon.

    But I have no idea what is the difference between
    new and old logic / memory-treatment,
    and what concern about tasks.
    and why window-icons on task-bar are suffled.

    Why petit-freeze became longer ?
    …is it happen when the older-memoris are flashed ?

    I would like the petit-freeze to become shorter a time,
    and not to shuffle the icons on task-bar.

    machine spec:
    windows7 64bit
    firefox 40.0.3
    memory 4GB (Crhome runs lightly)
    1TB hdd (not ssd)

    by the way, firefox on ubuntu14.04 became slowly,too
    like on Windows7. May be same reason.

    thank you.

  2. Movien said on July 11, 2015 at 4:29 pm

    This is wrong article and dumb.
    Actually firefox is killing my PC memory (ver 39), earlier it was better.
    While watching any video or movie, within 2mins reaching 3GB memory, and both PC and Firefox hanging/not responding.
    What a waste update from firefox.

  3. RossN said on July 10, 2015 at 11:34 pm

    I don’t know why I have the following problem with Firefox on my home system… but when I have left the computer idle for some time (10 mins?) I come back to a non-responding Firefox. I have to either restart it, or wait 20-30 secs before it responds.

  4. Brutus said on July 10, 2015 at 6:21 pm

    You can trigger compacting with this add-on.

  5. Ian Scrimgeour said on July 10, 2015 at 6:09 pm

    Keep up the good work Martin, I love the site.

  6. Ian Scrimgeour said on July 10, 2015 at 6:07 pm

    I stopped using Java about 2 years ago, I run Windows 8.1, and found that the earlier Beta version was susceptible to crashes with Java. I must admit I have hardly missed it and have had, touch wood, no crashes since then.

    1. ekerazha said on July 10, 2015 at 6:35 pm

      JavaScript and Java are completely different things.

  7. Terrine said on July 10, 2015 at 4:38 pm

    ‘Improvements’ that ‘improve’.

    Now that’s what I call improvement! :-)

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.