Skip to content

Commit c518481

Browse files
committed
Bug 1535403 - Take indirection into account for the CC optimizations for the outer window wrapper. r=peterv
Most wrapper cached C++ objects are held alive by their wrapper. The cycle collector takes advantage of this in many classes and ignores the C++ object if the wrapper is marked black. However, this is not true for the outer window's wrapper. Instead, the outer window's wrapper keeps the inner window alive. The inner window usually keeps its outer window alive, but not after it has been unlinked. For reasons I do not yet understand, the outer window's wrapper can be kept alive after the inner window it is a proxy for is unlinked. This patch fixes the cycle collector optimization for the outer window by only applying it if the outer window still has a weak reference to the inner window, which it will until the inner no longer holds the outer alive. This in turn fixes, or at least helps fix, window leaks seen intermittently when the lifetime of outer windows and docshells are tied together. The code comment is based on a review comment by peterv. Differential Revision: https://phabricator.services.mozilla.com/D27981 --HG-- extra : moz-landing-system : lando
1 parent f5e6644 commit c518481

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

dom/base/nsGlobalWindowOuter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,8 +1464,13 @@ bool nsGlobalWindowOuter::IsBlackForCC(bool aTracingNeeded) {
14641464
return false;
14651465
}
14661466

1467+
// Unlike most wrappers, the outer window wrapper is not a wrapper for
1468+
// the outer window. Instead, the outer window wrapper holds the inner
1469+
// window binding object, which in turn holds the nsGlobalWindowInner, which
1470+
// has a strong reference to the nsGlobalWindowOuter. We're using the
1471+
// mInnerWindow pointer as a flag for that whole chain.
14671472
return (nsCCUncollectableMarker::InGeneration(GetMarkedCCGeneration()) ||
1468-
HasKnownLiveWrapper()) &&
1473+
(mInnerWindow && HasKnownLiveWrapper())) &&
14691474
(!aTracingNeeded || HasNothingToTrace(ToSupports(this)));
14701475
}
14711476

0 commit comments

Comments
 (0)