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
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // Test-only module in order to register objects later inspected by
6 // the allocation tracker (in the same folder).
8 // We are going to store a weak reference to the passed objects,
9 // in order to prevent holding them in memory.
10 // Allocation tracker will then print detailed information
11 // about why these objects are still allocated.
16 * Request to track why the given object is kept in memory,
17 * later on, when retrieving all the watched object via getAllNodeIds.
19 export function track(obj) {
20 // We store a weak reference, so that we do force keeping the object in memory!!
21 objects.push(Cu.getWeakReference(obj));
25 * Return the NodeId's of all the objects passed via `track()` method.
27 * NodeId's are used by spidermonkey memory API to designates JS objects in head snapshots.
29 export function getAllNodeIds() {
30 // Filter out objects which have been freed already
33 .map(weak => weak.get())
35 // Convert objects from here instead of from allocation tracker in order
36 // to be from the shared system compartment and avoid trying to compute the NodeId
38 .map(ChromeUtils.getObjectNodeId)
43 * Used by tests to clear all tracked objects
45 export function clear() {