Bug 768901 - Don't double-count shared nsCSSStyleSheetInners. r=bz.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 09 Oct 2012 20:03:18 -0700
changeset 110178 b275f72aba112e4442d3f914ed880b60b26af05a
parent 110177 a7af99eb7bd51c2cfeb9541746c55aebf48351a3
child 110179 a7acfcb014f909a420a5d3a2e0d18d372393b8c9
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbz
bugs768901
milestone19.0a1
Bug 768901 - Don't double-count shared nsCSSStyleSheetInners. r=bz.
layout/style/nsCSSStyleSheet.cpp
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -858,20 +858,28 @@ nsCSSStyleSheet::RebuildChildList(css::R
 
 size_t
 nsCSSStyleSheet::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
 {
   size_t n = 0;
   const nsCSSStyleSheet* s = this;
   while (s) {
     n += aMallocSizeOf(s);
-    n += s->mInner->SizeOfIncludingThis(aMallocSizeOf);
 
-    // Measurement of the following members may be added later if DMD finds it is
-    // worthwhile:
+    // Each inner can be shared by multiple sheets.  So we only count the inner
+    // if this sheet is the first one in the list of those sharing it.  As a
+    // result, the first such sheet takes all the blame for the memory
+    // consumption of the inner, which isn't ideal but it's better than
+    // double-counting the inner.
+    if (s->mInner->mSheets[0] == s) {
+      n += s->mInner->SizeOfIncludingThis(aMallocSizeOf);
+    }
+
+    // Measurement of the following members may be added later if DMD finds it
+    // is worthwhile:
     // - s->mTitle
     // - s->mMedia
     // - s->mRuleCollection
     // - s->mRuleProcessors
     //
     // The following members are not measured:
     // - s->mOwnerRule, because it's non-owning