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 import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";
7 // This listens for the message "browser-test:collect-request". When it gets it,
8 // it runs some GCs and CCs, then prints out a message indicating the collections
9 // are complete. Mochitest uses this information to determine when windows and
10 // docshells should be destroyed.
12 export var ContentCollector = {
14 let processType = Services.appinfo.processType;
15 if (processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
16 // In the main process, we handle triggering collections in browser-test.js
20 Services.cpmm.addMessageListener("browser-test:collect-request", this);
23 receiveMessage(aMessage) {
24 switch (aMessage.name) {
25 case "browser-test:collect-request":
26 Services.obs.notifyObservers(null, "memory-pressure", "heap-minimize");
31 let shutdownCleanup = aCallback => {
32 Cu.schedulePreciseShrinkingGC(() => {
33 // Run the GC and CC a few times to make sure that as much
34 // as possible is freed.
41 shutdownCleanup(() => {
43 shutdownCleanup(() => {
54 let pid = Services.appinfo.processID;
55 dump("Completed ShutdownLeaks collections in process " + pid + "\n");
57 Services.cpmm.removeMessageListener("browser-test:collect-request", this);
61 ContentCollector.init();