From 8acc38570467e2ed447f302863effd6a68c82367 Mon Sep 17 00:00:00 2001 From: "myk@mozilla.org" Date: Thu, 21 Jun 2007 14:19:15 -0700 Subject: [PATCH] bug 385086: another followup patch with a better mechanism for nulling XPCOM components that could potentially cause leaks r=sayrer --- .../base/content/browser-contentPrefSink.js | 17 +++++----- browser/base/content/browser-textZoom.js | 7 ++-- .../contentprefs/src/nsContentPrefService.js | 33 +++++-------------- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/browser/base/content/browser-contentPrefSink.js b/browser/base/content/browser-contentPrefSink.js index 4142e3cd34d..0ea00dd74f2 100755 --- a/browser/base/content/browser-contentPrefSink.js +++ b/browser/base/content/browser-contentPrefSink.js @@ -84,14 +84,15 @@ var ContentPrefSink = { gBrowser.removeEventListener("DOMContentLoaded", this, false); gBrowser.removeProgressListener(this); - // Delete reference to an XPCOM component to make sure we don't leak it - // (although we haven't observed leakage in tests). - this.__cps = null; - - // Delete references to observers to avoid cycles with those that refer - // to us and don't remove themselves from the observer pool. - this._observers = {}; - this._genericObservers = []; + // Delete references to XPCOM components to make sure we don't leak them + // (although we haven't observed leakage in tests). Also delete references + // in _observers and _genericObservers to avoid cycles with those that + // refer to us and don't remove themselves from those observer pools. + for (var i in this) { + try { this[i] = null } + // Ignore "setting a property that has only a getter" exceptions. + catch(ex) {} + } }, diff --git a/browser/base/content/browser-textZoom.js b/browser/base/content/browser-textZoom.js index 24ab021d953..72bd44ab805 100755 --- a/browser/base/content/browser-textZoom.js +++ b/browser/base/content/browser-textZoom.js @@ -136,8 +136,11 @@ var TextZoom = { // Delete references to XPCOM components to make sure we don't leak them // (although we haven't observed leakage in tests). - this.__cps = null; - this.__prefBranch = null; + for (var i in this) { + try { this[i] = null } + // Ignore "setting a property that has only a getter" exceptions. + catch(ex) {} + } }, diff --git a/toolkit/components/contentprefs/src/nsContentPrefService.js b/toolkit/components/contentprefs/src/nsContentPrefService.js index 49380ec0976..293935fd001 100755 --- a/toolkit/components/contentprefs/src/nsContentPrefService.js +++ b/toolkit/components/contentprefs/src/nsContentPrefService.js @@ -82,31 +82,14 @@ ContentPrefService.prototype = { this._observerSvc.removeObserver(this, "xpcom-shutdown"); // Delete references to XPCOM components to make sure we don't leak them - // (although we haven't observed leakage in tests). - this.__observerSvc = null; - this.__consoleSvc = null; - this._grouper = null; - this.__stmtSelectPref = null; - this.__stmtSelectGlobalPref = null; - this.__stmtSelectGroupID = null; - this.__stmtInsertGroup = null; - this.__stmtSelectSettingID = null; - this.__stmtInsertSetting = null; - this.__stmtSelectPrefID = null; - this.__stmtSelectGlobalPrefID = null; - this.__stmtInsertPref = null; - this.__stmtUpdatePref = null; - this.__stmtDeletePref = null; - this.__stmtDeleteSettingIfUnused = null; - this.__stmtDeleteGroupIfUnused = null; - this.__stmtSelectPrefs = null; - this.__stmtSelectGlobalPrefs = null; - this._dbConnection = null; - - // Delete references to observers to avoid cycles with those that refer - // to us and don't remove themselves from the observer pool. - this._observers = {}; - this._genericObservers = []; + // (although we haven't observed leakage in tests). Also delete references + // in _observers and _genericObservers to avoid cycles with those that + // refer to us and don't remove themselves from those observer pools. + for (var i in this) { + try { this[i] = null } + // Ignore "setting a property that has only a getter" exceptions. + catch(ex) {} + } },