diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 807b3b94b12d..dbfbafeb797c 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -238,6 +238,16 @@ KillTimers() nsJSContext::KillInterSliceGCTimer(); } +// If we collected a substantial amount of cycles, poke the GC since more objects +// might be unreachable now. +static bool +NeedsGCAfterCC() +{ + return sCCollectedWaitingForGC > 250 || + sLikelyShortLivingObjectsNeedingGC > 2500 || + sNeedsGCAfterCC; +} + class nsJSEnvironmentObserver MOZ_FINAL : public nsIObserver { public: @@ -263,6 +273,12 @@ nsJSEnvironmentObserver::Observe(nsISupports* aSubject, const char* aTopic, nsJSContext::NonCompartmentGC, nsJSContext::ShrinkingGC); nsJSContext::CycleCollectNow(); + if (NeedsGCAfterCC()) { + nsJSContext::GarbageCollectNow(JS::gcreason::MEM_PRESSURE, + nsJSContext::NonIncrementalGC, + nsJSContext::NonCompartmentGC, + nsJSContext::ShrinkingGC); + } } else if (!nsCRT::strcmp(aTopic, "quit-application")) { sShuttingDown = true; KillTimers(); @@ -2215,11 +2231,7 @@ nsJSContext::EndCycleCollectionCallback(CycleCollectorResults &aResults) sCCollectedWaitingForGC += aResults.mFreedRefCounted + aResults.mFreedGCed; - // If we collected a substantial amount of cycles, poke the GC since more objects - // might be unreachable now. - if (sCCollectedWaitingForGC > 250 || - sLikelyShortLivingObjectsNeedingGC > 2500 || - sNeedsGCAfterCC) { + if (NeedsGCAfterCC()) { PokeGC(JS::gcreason::CC_WAITING); }