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.
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.
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
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.