Breakthrough: Mozilla To Eliminate Add-on Memory Leaks

Martin Brinkmann
May 8, 2012
Updated • May 8, 2012
Firefox, Firefox add-ons
|
11

When it comes to the Firefox web browser, add-ons are without doubt one of the most important feature that are making the browser attractive to a lot of users. It is in fact still a feature that is setting the browser apart from other web browsers, be it Opera or Chrome. Add-ons can however also cause issues for users of the browser, especially when it comes to memory leaks. This in fact may be one of the reasons why users see the browser's memory use grow over time on the operating system.

To make matters worse, Firefox is still seen by many as the browser with the worst memory management, even though that is not really the case, if you level the playing field. Depending on the add-ons installed, and versions of the browser used, results may vary.

Breakthrough

Mozilla very recently made a breakthrough that has not yet been picked up by any tech news site out there.  In fixing the memory leak, Mozilla developer Kyle Huey explains how he fixed add-on memory leaks once and for all in the web browser.

My approach takes advantage of the fact that chrome code lives in a separate compartment from web page code.  This means that every reference from chrome code to content code goes through a cross-compartment wrapper, which we maintain in a list.  When the page is navigated, or a tab is closed, we reach into chrome compartment and grab this list.  We go through this list and “cut” all of the wrappers that point to objects in the page we’re getting rid of.  The garbage collector can then reclaim the memory used by the page that is now gone.

In layman terms, Firefox is now blocking add-ons from accessing content in the browser that does not exist anymore.

Memory usage over time of a specifically prepared test suite has dropped by 80%. Instead of climbing up to 800 or 900 Megabytes at the end of the day, Firefox would now use about 230 Megabytes instead. Even on systems with lots of memory, users will still see benefits due to garbage collection and cycle collection pauses.

However, what if the user has a high-end machine with 16GB of RAM?  Then paging isn’t an issue.  But this improvement will still be a big deal on such a machine.  This is because garbage collection and cycle collection cause pauses, and the length of the pauses are roughly proportional to the amount of live heap memory.  (Incremental garbage collection will soon be enabled, which will result in smaller garbage collection pauses, but there are no plans for incremental cycle collection and so cycle collection pauses will still be relevant.)  So even on high-end machines with lots of RAM, leaks can greatly hurt browser performance.

There is however still one issue that Mozilla needs to get their heads around. The patch managed to prevent the single most common class of add-on leaks, but has caused another leak to come forward that is caused by add-ons that have been compiled with an older version of the Add-on SDK. It may take some time before that issue is resolved by the developers, but once that is resolved, you can wave goodbye to add-on memory leaks.

Firefox users who want to try a version of the browser with the feature enabled, can download one of the latest Nightly builds from Mozilla to do so. These are cutting edge development builds, and not suitable for productive environments.  If things go along as planned, we will see the feature as early as in Firefox 15 which is scheduled for an August 28, 2012 release.

Closing Words

Fixing add-on memory leaks is an important step for Mozilla, as it not only will make the browser faster for a lot of users, it will also change the perception that users have when they use it. Things are looking a lot brighter now. (thanks Adam for the tip)

Advertisement

Tutorials & Tips


Previous Post: «
Next Post: «

Comments

  1. Unified Field said on July 5, 2012 at 5:55 pm
    Reply

    MemShrink & Snappy have again brought Firefox to a level where it is enjoyable to use.
    Can’t wait for SuperSnappy and Electrolysis tho

  2. Mystique said on May 9, 2012 at 9:25 am
    Reply

    That sounds great!

    I can’t wait to test it, I have been using firefox since the 0.x phoenix days and there have been some really great highs come from mozilla but over the past few years there has been a lot of lows whilst firefox has become more robust and the scope of web development has escalated quite a bit since firefox has saidly become more and more sluggish in respect to memory management and stability so much so that at this point I am using opera and I must say my net enjoyment seems sacrificed on this thing, I have also looked to chrome (chrome plus, and SW Iron) for a different experience and something to fill the void temporarily until firefox becomes stable again.
    What I would like to see is some form of task manager similar to chrome that can somewhat benchmark addons, extensions and allow you to gather statistics from each tab and trace down leaks and problems in a more efficient manner therefore every layman can min/max their browser to perform at its optimum.

    1. Martin Brinkmann said on May 9, 2012 at 9:44 am
      Reply

      I agree, it would be really cool to see how individual add-ons, themes and the like perform, for instance to spot add-ons that use to much bandwidth or cpu.

  3. Roman ShaRP said on May 8, 2012 at 8:42 pm
    Reply

    I’m skeptic, so first I want to see how it works in stable build ;)

  4. Gonzo said on May 8, 2012 at 8:27 pm
    Reply

    Great news for those who leave they’re browser open all day?? For those that open and close their browser regularly memory leaks really aren’t an issue.

    Moving devs to a newer SDK should be manageable. A simple notice prior to the next release or the add-on falls victim to being labeled incompatible.

    My wish list for Firefox is a tight sandbox like Chromium and a mandatory Low Integrity level. Then again, I don’t run as an Admin so it’s not a huge deal for me.

  5. bastik said on May 8, 2012 at 7:42 pm
    Reply

    That’s something to talk about. That’s what developers should highlight.

  6. Crodol said on May 8, 2012 at 7:34 pm
    Reply

    Finally the developers changed something that actually needed change!!!

  7. Jim said on May 8, 2012 at 3:01 pm
    Reply

    Great news. Now if they’ll just quit trying to look like Chrome…

  8. Ademas Z3MN said on May 8, 2012 at 2:43 pm
    Reply

    Yes! This is it! I love you Mozilla :D

  9. Yoav said on May 8, 2012 at 12:52 pm
    Reply

    About time – for me memory leaks are the only serious defect in this great browser. Well, besides the new and crazy 24 hour update cycle…

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.