From 0518b12d34e16fbf9802e82389d1db076f1bcb4e Mon Sep 17 00:00:00 2001 From: liazy Date: Fri, 20 Sep 2013 11:53:02 +0100 Subject: [PATCH] Fix memory leaks. - MultiSelect: Form events not being unbound on destroy. - Filter: Document events not being unbound on destroy. - Filter: Removed circular reference that prevented garbage collection. Have not updated minified javascript! --- src/jquery.multiselect.filter.js | 6 +++--- src/jquery.multiselect.js | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/jquery.multiselect.filter.js b/src/jquery.multiselect.filter.js index 1560700..b1e5f2e 100644 --- a/src/jquery.multiselect.filter.js +++ b/src/jquery.multiselect.filter.js @@ -63,7 +63,7 @@ var _self = this; // do not include hidden elems if the menu isn't open. - var selector = instance._isOpen ? ':disabled, :hidden' : ':disabled'; + var selector = _self._isOpen ? ':disabled, :hidden' : ':disabled'; $inputs = $inputs .not(selector) @@ -91,14 +91,14 @@ }; // rebuild cache when multiselect is updated - var doc = $(document).bind('multiselectrefresh', $.proxy(function() { + var doc = $(document).bind('multiselectrefresh.'+ instance._namespaceID, $.proxy(function() { this.updateCache(); this._handler(); }, this)); // automatically reset the widget on close? if(this.options.autoReset) { - doc.bind('multiselectclose', $.proxy(this._reset, this)); + doc.bind('multiselectclose.'+ instance._namespaceID, $.proxy(this._reset, this)); } }, diff --git a/src/jquery.multiselect.js b/src/jquery.multiselect.js index a1cd9e4..cef6e4e 100644 --- a/src/jquery.multiselect.js +++ b/src/jquery.multiselect.js @@ -417,7 +417,7 @@ // restored to their defaultValue prop on form reset, and the reset // handler fires before the form is actually reset. delaying it a bit // gives the form inputs time to clear. - $(this.element[0].form).bind('reset.multiselect', function() { + $(this.element[0].form).bind('reset.' + this._namespaceID, function() { setTimeout($.proxy(self.refresh, self), 10); }); }, @@ -644,6 +644,7 @@ // unbind events $doc.unbind(this._namespaceID); + $(this.element[0].form).unbind(this._namespaceID); this.button.remove(); this.menu.remove();