Bug 657480: Clean up after TelemetryPing.js r=mak
authorTaras Glek <tglek@mozilla.com>
Mon, 16 May 2011 16:03:36 -0700
changeset 69588 3e7a21049b6cef347c1b7307507cbaf2965f9b4a
parent 69587 b54fc6516c0c13af51508a89a9f3321b7e120243
child 69589 0a1e7ec7e2684d21d19a017663c373b0518076c4
push id20033
push usertglek@mozilla.com
push dateMon, 16 May 2011 23:03:52 +0000
treeherdermozilla-central@3e7a21049b6c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs657480
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 657480: Clean up after TelemetryPing.js r=mak
toolkit/components/telemetry/TelemetryPing.js
--- a/toolkit/components/telemetry/TelemetryPing.js
+++ b/toolkit/components/telemetry/TelemetryPing.js
@@ -230,33 +230,49 @@ TelemetryPing.prototype = {
       return;
   
     let self = this;
     this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     let timerCallback = function() {
       let idleService = Cc["@mozilla.org/widget/idleservice;1"].
                         getService(Ci.nsIIdleService);
       idleService.addIdleObserver(self, TELEMETRY_INTERVAL);
-      Services.obs.addObserver(self, "idle-daily", null);
+      Services.obs.addObserver(self, "idle-daily", false);
+      Services.obs.addObserver(self, "profile-before-change", false);
       self.gatherMemory();
+      delete self._timer
     }
     this._timer.initWithCallback(timerCallback, TELEMETRY_DELAY, Ci.nsITimer.TYPE_ONE_SHOT);
   },
 
+  /** 
+   * Remove observers to avoid leaks
+   */
+  uninstall: function uninstall() {
+    let idleService = Cc["@mozilla.org/widget/idleservice;1"].
+                      getService(Ci.nsIIdleService);
+    idleService.removeIdleObserver(this, TELEMETRY_INTERVAL);
+    Services.obs.removeObserver(this, "idle-daily");
+    Services.obs.removeObserver(this, "profile-before-change");
+  },
+
   /**
    * This observer drives telemetry.
    */
   observe: function (aSubject, aTopic, aData) {
     // Allows to change the server for testing
     var server = this._server;
 
     switch (aTopic) {
     case "profile-after-change":
       this.setup();
       break;
+    case "profile-before-change":
+      this.uninstall();
+      break;
     case "idle":
       this.gatherMemory();
       break;
     case "test-ping":
       server = aData;
       // fall through
     case "idle-daily":
       this.send(aTopic, server);