[gnome-documents/gnome-3-16] mainToolbar: Disconnect from DocumentManager when destroyed



commit ca739d66b24593d1b080fb17e1f110065db431de
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Apr 10 13:37:20 2015 +0200

    mainToolbar: Disconnect from DocumentManager when destroyed
    
    We destroy and re-create the toolbar on mode changes. Therefore, we
    can not rely on disconnectAll to break all the connections when the
    main window is finally gone. We need to break the connections
    immediately when the toolbar is destroyed.
    
    Failure to remove the signal handlers will lead to a spurious reference
    being kept on the widget, which will prevent it from being garbage
    collected.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=747506

 src/mainToolbar.js |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 295603f..ad7166d 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -53,13 +53,22 @@ const MainToolbar = new Lang.Class({
         if (this.searchbar)
             this.widget.add(this.searchbar.widget);
 
-        Application.documentManager.connect('load-started', Lang.bind(this,
+        let loadStartedId = Application.documentManager.connect('load-started', Lang.bind(this,
             function() {
                 this._handleEvent = true;
             }));
 
-        Application.documentManager.connect('load-error', Lang.bind(this, this._onLoadErrorOrPassword));
-        Application.documentManager.connect('password-needed', Lang.bind(this, this._onLoadErrorOrPassword));
+        let loadErrorId = Application.documentManager.connect('load-error',
+            Lang.bind(this, this._onLoadErrorOrPassword));
+        let passwordNeededId = Application.documentManager.connect('password-needed',
+            Lang.bind(this, this._onLoadErrorOrPassword));
+
+        this.widget.connect('destroy', Lang.bind(this,
+            function() {
+                Application.documentManager.disconnect(loadStartedId);
+                Application.documentManager.disconnect(loadErrorId);
+                Application.documentManager.disconnect(passwordNeededId);
+            }));
     },
 
     _onLoadErrorOrPassword: function() {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]