Bug 1292218 - Run collectors more in reftests. r=jmaher
MozReview-Commit-ID: E7TQpBMeiVB
--- a/layout/tools/reftest/reftest-content.js
+++ b/layout/tools/reftest/reftest-content.js
@@ -1,14 +1,16 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- /
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+// This file is used both for e10s and non-e10s reftests.
+
var CC = Components.classes;
const CI = Components.interfaces;
const CR = Components.results;
const CU = Components.utils;
const XHTML_NS = "http://www.w3.org/1999/xhtml";
const DEBUG_CONTRACTID = "@mozilla.org/xpcom/debug;1";
@@ -682,16 +684,37 @@ function OnDocumentLoad(event)
}
if (currentDoc.location.href != gCurrentURL) {
LogInfo("OnDocumentLoad fired for previous document");
// Ignore load events for previous documents.
return;
}
+ // Reftests open and close windows very quickly, so that the usual
+ // browser heuristics for running the garbage collector (GC) and
+ // cycle collector (CC) do not work well. This causes memory usage
+ // to increase, which can cause tests to run out of memory, or
+ // time out because we end up freeing many windows at once during
+ // a test, which can take a long time.
+ //
+ // To combat this, call |runNextCollectorTimer();| a few
+ // times. This makes us run incremental GC or CC more eagerly,
+ // reducing memory usage, while ensuring that we are still
+ // somewhat testing incremental collection.
+ //
+ // There's no specific reason for calling this four times in a
+ // row, other than it seemed to help more than calling it less
+ // times, and it helped as much as calling it five times. Each
+ // call should only take 5ms to 40ms.
+ windowUtils().runNextCollectorTimer();
+ windowUtils().runNextCollectorTimer();
+ windowUtils().runNextCollectorTimer();
+ windowUtils().runNextCollectorTimer();
+
// Collect all editable, spell-checked elements. It may be the case that
// not all the elements that match this selector will be spell checked: for
// example, a textarea without a spellcheck attribute may have a parent with
// spellcheck=false, or script may set spellcheck=false on an element whose
// markup sets it to true. But that's OK since onSpellCheck detects the
// absence of spell checking, too.
var querySelector =
'*[class~="spell-checked"],' +