From 3521a4dc641ad6b62f703e15edc76237ac1e770c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 11 May 2011 16:09:50 -0700 Subject: [PATCH] Bug 655583 - In about:memory, only remove the observer if it's been added, in order to avoid an assertion and/or exception. r=bz. --- .../components/aboutmemory/content/aboutMemory.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/toolkit/components/aboutmemory/content/aboutMemory.js b/toolkit/components/aboutmemory/content/aboutMemory.js index 1efffff9598..ebc197e93ba 100644 --- a/toolkit/components/aboutmemory/content/aboutMemory.js +++ b/toolkit/components/aboutmemory/content/aboutMemory.js @@ -46,6 +46,8 @@ const Cu = Components.utils; // non-standard URL. var gVerbose = (location.href.split(/[\?,]/).indexOf("verbose") !== -1); +var gAddedObserver = false; + function onLoad() { var os = Cc["@mozilla.org/observer-service;1"]. @@ -53,15 +55,21 @@ function onLoad() os.notifyObservers(null, "child-memory-reporter-request", null); os.addObserver(ChildMemoryListener, "child-memory-reporter-update", false); + gAddedObserver = true; update(); } function onUnload() { - var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - os.removeObserver(ChildMemoryListener, "child-memory-reporter-update"); + // We need to check if the observer has been added before removing; in some + // circumstances (eg. reloading the page quickly) it might not have because + // onLoad might not fire. + if (gAddedObserver) { + var os = Cc["@mozilla.org/observer-service;1"]. + getService(Ci.nsIObserverService); + os.removeObserver(ChildMemoryListener, "child-memory-reporter-update"); + } } function ChildMemoryListener(aSubject, aTopic, aData)