Bug 887889 - Clean up ContentPrefServiceChild on xpcom-shutdown r?mak
I'm not sure why this became necessary as a result of migrating to
Sqlite.jsm, but this is the only way I've found to eliminate
leaks from the tab process on shutdown. These leaks occur when
the child process requests something from the ContentPrefService2
but shuts down before it gets its response.
MozReview-Commit-ID: 2Haks17D6Em
--- a/toolkit/components/contentprefs/ContentPrefServiceChild.jsm
+++ b/toolkit/components/contentprefs/ContentPrefServiceChild.jsm
@@ -57,16 +57,23 @@ var ContentPrefServiceChild = {
// Map from random ID string -> CallbackCaller, per request
_requests: new Map(),
init() {
Services.cpmm.addMessageListener("ContentPrefs:HandleResult", this);
Services.cpmm.addMessageListener("ContentPrefs:HandleError", this);
Services.cpmm.addMessageListener("ContentPrefs:HandleCompletion", this);
+ Services.obs.addObserver(this, "xpcom-shutdown");
+ },
+
+ observe() {
+ Services.obs.removeObserver(this, "xpcom-shutdown");
+ delete this._observers;
+ delete this._requests;
},
receiveMessage(msg) {
let data = msg.data;
let callback;
switch (msg.name) {
case "ContentPrefs:HandleResult":
callback = this._requests.get(data.requestId);