{"id":1046,"date":"2011-07-20T12:45:45","date_gmt":"2011-07-20T01:45:45","guid":{"rendered":"http:\/\/blog.mozilla.org\/nnethercote\/?p=1046"},"modified":"2011-12-01T08:58:00","modified_gmt":"2011-11-30T21:58:00","slug":"zombie-compartments-recognize-and-report-them-stop-the-screaming","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/nnethercote\/2011\/07\/20\/zombie-compartments-recognize-and-report-them-stop-the-screaming\/","title":{"rendered":"Zombie compartments!  Recognize and report them.  Stop the screaming."},"content":{"rendered":"<p><strong>Update (November 30, 2011):<\/strong> <em>I wrote a <a href=\"https:\/\/developer.mozilla.org\/en\/Zombie_compartments\">wiki page<\/a> about zombie compartments.\u00a0 It&#8217;s much clearer than this post, you should read it instead.<\/em><\/p>\n<p><strong>Update (July 31, 2011):<\/strong> <em>This blog post has been linked to from <a href=\"http:\/\/mozilla.org\">mozilla.org<\/a>&#8216;s front page.\u00a0 Although any help in improving Firefox&#8217;s memory usage is very welcome, please note that this post was aimed at Firefox developers and other technically-inclined users, and I wasn&#8217;t expecting its existence to be publicized so widely.\u00a0\u00a0 Furthermore, the per-compartment reporters that help identify zombie compartments were only added to Firefox 7 (currently in the <a href=\"http:\/\/aurora.mozilla.org\/\">Aurora<\/a> channel), and several existing bugs that cause zombie compartments have been subsequently fixed in the Firefox 8 development code.\u00a0 This means the hunting of zombie compartments is a sport best left to those who either are using <a href=\"http:\/\/nightly.mozilla.org\/\">Nightly builds<\/a> or their own development builds of Firefox.<\/em><\/p>\n<p>Firefox&#8217;s JavaScript memory is segregated into <em><a href=\"http:\/\/andreasgal.com\/2010\/10\/13\/compartments\/\">compartments<\/a><\/em>.\u00a0 Roughly speaking, all memory used by JavaScript code that is from a particular origin (i.e. website) goes into its own compartment.\u00a0 Firefox&#8217;s own JavaScript code also gets one or more compartments.\u00a0 Compartments improve security and memory locality.<\/p>\n<p><a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=661474\">Per-compartment memory reporters<\/a> allow you to look at <a href=\"about:memory\">about:memory<\/a> to see what compartments are present.\u00a0 Once you close a tab containing a web page, all the compartments associated with that web page should disappear.\u00a0 (But note that they won&#8217;t necessarily disappear immediately;\u00a0 garbage collection and\/or cycle collection has to run first.)<\/p>\n<p>Sometimes this doesn&#8217;t happen and you end up with a <em><a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=668871\">Zombie Compartment<\/a><\/em>.\u00a0 This shouldn&#8217;t happen, and it indicates a bug.\u00a0 It also makes children and 1950s B-movie actresses scream.<\/p>\n<p style=\"text-align: center;\">\u00a0<a href=\"http:\/\/blog.mozilla.org\/nnethercote\/files\/2011\/07\/woman-screaming.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter\" title=\"woman-screaming\" src=\"http:\/\/blog.mozilla.org\/nnethercote\/files\/2011\/07\/woman-screaming.jpg\" alt=\"1950s B-movie woman screaming\" width=\"240\" height=\"204\" \/><\/a><\/p>\n<p>If you notice Zombie Compartments while browsing, please report them to <a href=\"https:\/\/wiki.mozilla.org\/Performance\/MemShrink\">The Authorities<\/a>.\u00a0 Here are some steps you can follow when reporting one that will increase the chance it&#8217;ll be hunted down.<\/p>\n<ul>\n<li>First, you should use <a href=\"about:memory?verbose\">about:memory?verbose<\/a> for diagnosis.\u00a0 You want the &#8220;?verbose&#8221; suffix (which you can also get to by clicking the &#8220;More verbose&#8221; link at the bottom of <a href=\"about:memory\">about:memory<\/a>) otherwise small compartments might be omitted.<\/li>\n<li>Second, beware that many sites utilize scripts from other origins.\u00a0 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 <a href=\"about:memory?verbose\">about:memory?verbose<\/a> and one other tab, then close that other tab, then hit &#8220;minimize memory usage&#8221; at the bottom of <a href=\"about:memory?verbose\">about:memory?verbose<\/a> several times to force multiple garbage and cycle collections.\u00a0 (Sometimes hitting it once isn&#8217;t enough, I&#8217;m not sure why.)\u00a0 If the compartment remains, it&#8217;s very likely a Zombie Compartment.<\/li>\n<li>After that, try waiting a while, say 10 or 20 minutes, then try the &#8220;minimize memory usage&#8221; button again.\u00a0 Some Zombie Compartments stick around for a <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=671053\">limited time<\/a> before disappearing;\u00a0 others are <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=669730\">immortal<\/a>, and it&#8217;s useful to know which is which.<\/li>\n<li>Some Zombie Compartments are <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=672619\">caused by<\/a> add-ons.\u00a0 So if you have add-ons enabled, please try to reproduce in <a href=\"http:\/\/support.mozilla.com\/en-US\/kb\/Safe%20Mode\">safe mode<\/a>, which disables them.\u00a0 If you can identify, by disabling them one at a time, a single add-on that is responsible, that is extremely helpful.\u00a0 Zombie compartments that are caused by add-ons are definitely interesting, but their importance depends on the popularity of the add-on.<\/li>\n<li>Finally, please file a bug that includes all the information you&#8217;ve gathered, add &#8220;[MemShrink]&#8221; to its whiteboard, and mark it as blocking <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=668871\">bug 668871<\/a>.\u00a0 Attaching the full contents of <a href=\"about:memory?verbose\">about:memory?verbose<\/a> is very helpful.\u00a0 See <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=669545\">bug 669545<\/a> for an example.<\/li>\n<\/ul>\n<p>Please, stop the screaming.\u00a0 Report Zombie Compartments to The Authorities.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update (November 30, 2011): I wrote a wiki page about zombie compartments.\u00a0 It&#8217;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&#8216;s front page.\u00a0 Although any help in improving Firefox&#8217;s memory usage is very welcome, please note that this post was [&hellip;]<\/p>\n","protected":false},"author":139,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4554,30,4544,4546],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/1046"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/users\/139"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/comments?post=1046"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/1046\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/media?parent=1046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/categories?post=1046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/tags?post=1046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}