mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-25 15:43:10 -10:00
There are two leaks addressed in this commit: 1. The thread actor's `_debuggerSourcesSeen` set was never cleared. This set exists only as a performance optimization to speed up `_addSource` in cases where we've already added the source. Unfortunately, this set wasn't getting cleared when we cleared debuggees out and it ended up keeping the `Debugger.Source`, its referent, and transitively its referent's global alive. I figured it was simpler to make it a `WeakSet` than to add it as a special case in `ThreadActor.prototype._clearDebuggees` and manage the lifetimes by hand. I think this fits well with its intended use as an ephemeral performance optimization. 2. Due to a logic error, we were not clearing debuggees in the memory actor's `Debugger` instance on navigations. This isn't really a "proper" leak, in that if you forced a GC, the old debuggees would go away as `Debugger` holds them weakly, however if there was no GC between navigations, then you could still see the old windows (and everything they "retained") as roots in the snapshot. This issue is straightforward to fix once identified: ensure that `_clearDebuggees` is actually called on navigation. Finally, this commit adds a test that we don't leak Window objects when devtools are open and we keep refreshing a tab. When it fails, it prints out the leaking window's retaining paths.
93 lines
3.2 KiB
JavaScript
93 lines
3.2 KiB
JavaScript
/* 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/. */
|
|
"use strict";
|
|
|
|
const { memorySpec } = require("devtools/shared/specs/memory");
|
|
const { Task } = require("devtools/shared/task");
|
|
const protocol = require("devtools/shared/protocol");
|
|
|
|
loader.lazyRequireGetter(this, "FileUtils",
|
|
"resource://gre/modules/FileUtils.jsm", true);
|
|
loader.lazyRequireGetter(this, "HeapSnapshotFileUtils",
|
|
"devtools/shared/heapsnapshot/HeapSnapshotFileUtils");
|
|
|
|
const MemoryFront = protocol.FrontClassWithSpec(memorySpec, {
|
|
initialize: function (client, form, rootForm = null) {
|
|
protocol.Front.prototype.initialize.call(this, client, form);
|
|
this._client = client;
|
|
this.actorID = form.memoryActor;
|
|
this.heapSnapshotFileActorID = rootForm
|
|
? rootForm.heapSnapshotFileActor
|
|
: null;
|
|
this.manage(this);
|
|
},
|
|
|
|
/**
|
|
* Save a heap snapshot, transfer it from the server to the client if the
|
|
* server and client do not share a file system, and return the local file
|
|
* path to the heap snapshot.
|
|
*
|
|
* Note that this is safe to call for actors inside sandoxed child processes,
|
|
* as we jump through the correct IPDL hoops.
|
|
*
|
|
* @params Boolean options.forceCopy
|
|
* Always force a bulk data copy of the saved heap snapshot, even when
|
|
* the server and client share a file system.
|
|
*
|
|
* @params {Object|undefined} options.boundaries
|
|
* The boundaries for the heap snapshot. See
|
|
* ThreadSafeChromeUtils.webidl for more details.
|
|
*
|
|
* @returns Promise<String>
|
|
*/
|
|
saveHeapSnapshot: protocol.custom(Task.async(function* (options = {}) {
|
|
const snapshotId = yield this._saveHeapSnapshotImpl(options.boundaries);
|
|
|
|
if (!options.forceCopy &&
|
|
(yield HeapSnapshotFileUtils.haveHeapSnapshotTempFile(snapshotId))) {
|
|
return HeapSnapshotFileUtils.getHeapSnapshotTempFilePath(snapshotId);
|
|
}
|
|
|
|
return yield this.transferHeapSnapshot(snapshotId);
|
|
}), {
|
|
impl: "_saveHeapSnapshotImpl"
|
|
}),
|
|
|
|
/**
|
|
* Given that we have taken a heap snapshot with the given id, transfer the
|
|
* heap snapshot file to the client. The path to the client's local file is
|
|
* returned.
|
|
*
|
|
* @param {String} snapshotId
|
|
*
|
|
* @returns Promise<String>
|
|
*/
|
|
transferHeapSnapshot: protocol.custom(function (snapshotId) {
|
|
if (!this.heapSnapshotFileActorID) {
|
|
throw new Error("MemoryFront initialized without a rootForm");
|
|
}
|
|
|
|
const request = this._client.request({
|
|
to: this.heapSnapshotFileActorID,
|
|
type: "transferHeapSnapshot",
|
|
snapshotId
|
|
});
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const outFilePath =
|
|
HeapSnapshotFileUtils.getNewUniqueHeapSnapshotTempFilePath();
|
|
const outFile = new FileUtils.File(outFilePath);
|
|
|
|
const outFileStream = FileUtils.openSafeFileOutputStream(outFile);
|
|
request.on("bulk-reply", Task.async(function* ({ copyTo }) {
|
|
yield copyTo(outFileStream);
|
|
FileUtils.closeSafeFileOutputStream(outFileStream);
|
|
resolve(outFilePath);
|
|
}));
|
|
});
|
|
})
|
|
});
|
|
|
|
exports.MemoryFront = MemoryFront;
|