Bug 1334874 use weak views to avoid treeselection.view cycle leaks draft
authorR Kent James <rkent@caspia.com>
Mon, 06 Feb 2017 12:36:00 +0100
changeset 47555 7b16e741744cd8cd3fb35daf9daf252c97d488fb
parent 47551 6483fa45f5b2330a94edbb24ff7235170bce7830
child 47556 ac1651948f29100a55d7419ecbf8f150f7e6b1eb
child 47617 764b9d37bc30a053d31bd9c71627b4d5668e4cad
push id4206
push useraleth@instantbird.org
push dateMon, 06 Feb 2017 23:41:32 +0000
treeherdertry-comm-central@85fe92c7da21 [default view] [failures only]
bugs1334874
Bug 1334874 use weak views to avoid treeselection.view cycle leaks
mailnews/base/util/jsTreeSelection.js
--- a/mailnews/base/util/jsTreeSelection.js
+++ b/mailnews/base/util/jsTreeSelection.js
@@ -80,27 +80,30 @@ JSTreeSelection.prototype = {
   _ranges: [],
   /**
    * The number of currently selected rows.
    */
   _count: 0,
 
   // In the case of the stand-alone message window, there's no tree, but
   // there's a view.
-  _view: null,
+  _viewWeak: null,
 
   get tree() {
     return this._treeBoxObject;
   },
   set tree(aTreeBoxObject) {
     this._treeBoxObject = aTreeBoxObject;
   },
 
   set view(aView) {
-    this._view = aView;
+    this._viewWeak = Cu.getWeakReference(aView);
+  },
+  get view() {
+    return (this._viewWeak) ? this._viewWeak.get() : null;
   },
   /**
    * Although the nsITreeSelection documentation doesn't say, what this method
    *  is supposed to do is check if the seltype attribute on the XUL tree is any
    *  of the following: "single" (only a single row may be selected at a time,
    *  "cell" (a single cell may be selected), or "text" (the row gets selected
    *  but only the primary column shows up as selected.)
    *
@@ -378,20 +381,20 @@ JSTreeSelection.prototype = {
   invertSelection: function JSTreeSelection_invertSelection() {
     throw new Error("Who really was going to use this?");
   },
 
   /**
    * Select all with no rows is a no-op, otherwise we select all and notify.
    */
   selectAll: function JSTreeSelection_selectAll() {
-    if (!this._view)
+    if (!this.view)
       return;
 
-    let view = this._view;
+    let view = this.view;
     let rowCount = view.rowCount;
 
     // no-ops-ville
     if (!rowCount)
       return;
 
     this._count = rowCount;
     this._ranges = [[0, rowCount - 1]];
@@ -585,17 +588,17 @@ JSTreeSelection.prototype = {
   _fireSelectionChanged: function JSTreeSelection__fireSelectionChanged() {
     // don't fire if we are suppressed; we will fire when un-suppressed
     if (this.selectEventsSuppressed)
       return;
     let view;
     if (this._treeBoxObject && this._treeBoxObject.view)
       view = this._treeBoxObject.view;
     else
-      view = this._view;
+      view = this.view;
 
     // We might not have a view if we're in the middle of setting up things
     if (view) {
       view = view.QueryInterface(Ci.nsITreeView);
       view.selectionChanged();
     }
   },