Update (November 30, 2011): I wrote a wiki page about zombie compartments. It’s much clearer than this post, you should read it instead.
Update (July 31, 2011): This blog post has been linked to from mozilla.org‘s front page. Although any help in improving Firefox’s memory usage is very welcome, please note that this post was aimed at Firefox developers and other technically-inclined users, and I wasn’t expecting its existence to be publicized so widely. Furthermore, the per-compartment reporters that help identify zombie compartments were only added to Firefox 7 (currently in the Aurora channel), and several existing bugs that cause zombie compartments have been subsequently fixed in the Firefox 8 development code. This means the hunting of zombie compartments is a sport best left to those who either are using Nightly builds or their own development builds of Firefox.
Per-compartment memory reporters allow you to look at about:memory to see what compartments are present. Once you close a tab containing a web page, all the compartments associated with that web page should disappear. (But note that they won’t necessarily disappear immediately; garbage collection and/or cycle collection has to run first.)
Sometimes this doesn’t happen and you end up with a Zombie Compartment. This shouldn’t happen, and it indicates a bug. It also makes children and 1950s B-movie actresses scream.
If you notice Zombie Compartments while browsing, please report them to The Authorities. Here are some steps you can follow when reporting one that will increase the chance it’ll be hunted down.
- First, you should use about:memory?verbose for diagnosis. You want the “?verbose” suffix (which you can also get to by clicking the “More verbose” link at the bottom of about:memory) otherwise small compartments might be omitted.
- Second, beware that many sites utilize scripts from other origins. Scripts from Google, Facebook and Twitter are particularly common. This means that the most reliable diagnosis of a Zombie Compartment occurs if you do the following: start Firefox anew, open about:memory?verbose and one other tab, then close that other tab, then hit “minimize memory usage” at the bottom of about:memory?verbose several times to force multiple garbage and cycle collections. (Sometimes hitting it once isn’t enough, I’m not sure why.) If the compartment remains, it’s very likely a Zombie Compartment.
- After that, try waiting a while, say 10 or 20 minutes, then try the “minimize memory usage” button again. Some Zombie Compartments stick around for a limited time before disappearing; others are immortal, and it’s useful to know which is which.
- Some Zombie Compartments are caused by add-ons. So if you have add-ons enabled, please try to reproduce in safe mode, which disables them. If you can identify, by disabling them one at a time, a single add-on that is responsible, that is extremely helpful. Zombie compartments that are caused by add-ons are definitely interesting, but their importance depends on the popularity of the add-on.
- Finally, please file a bug that includes all the information you’ve gathered, add “[MemShrink]” to its whiteboard, and mark it as blocking bug 668871. Attaching the full contents of about:memory?verbose is very helpful. See bug 669545 for an example.
Please, stop the screaming. Report Zombie Compartments to The Authorities.