1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
6 const { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm");
8 var EXPORTED_SYMBOLS = ["ContentCollector"];
10 // This listens for the message "browser-test:collect-request". When it gets it,
11 // it runs some GCs and CCs, then prints out a message indicating the collections
12 // are complete. Mochitest uses this information to determine when windows and
13 // docshells should be destroyed.
15 var ContentCollector = {
17 let processType = Services.appinfo.processType;
18 if (processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
19 // In the main process, we handle triggering collections in browser-test.js
23 Services.cpmm.addMessageListener("browser-test:collect-request", this);
26 receiveMessage(aMessage) {
27 switch (aMessage.name) {
28 case "browser-test:collect-request":
29 Services.obs.notifyObservers(null, "memory-pressure", "heap-minimize");
34 let shutdownCleanup = aCallback => {
35 Cu.schedulePreciseShrinkingGC(() => {
36 // Run the GC and CC a few times to make sure that as much
37 // as possible is freed.
44 shutdownCleanup(() => {
46 shutdownCleanup(() => {
57 let pid = Services.appinfo.processID;
58 dump("Completed ShutdownLeaks collections in process " + pid + "\n");
60 Services.cpmm.removeMessageListener("browser-test:collect-request", this);
63 ContentCollector.init();