From 901478925821d39bca92d45e6d378318374bbbd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 20 Aug 2014 15:54:31 -0400 Subject: [PATCH 1/3] Widget: Avoid memory leaks when unbinding events with `._off()` Ref #10056 --- ui/widget.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ui/widget.js b/ui/widget.js index d5a76c67dab..6ef161591f5 100644 --- a/ui/widget.js +++ b/ui/widget.js @@ -442,8 +442,14 @@ $.Widget.prototype = { }, _off: function( element, eventName ) { - eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace; + eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + + this.eventNamespace; element.unbind( eventName ).undelegate( eventName ); + + // Clear the stack to avoid memory leaks (#10056) + this.bindings = $( this.bindings.not( element ).get() ); + this.focusable = $( this.focusable.not( element ).get() ); + this.hoverable = $( this.hoverable.not( element ).get() ); }, _delay: function( handler, delay ) { From e0e89c8732de185e06c710049694fc17d659ddcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 20 Aug 2014 15:57:12 -0400 Subject: [PATCH 2/3] Tabs: Avoid memory leak during refresh Fixes #10056 --- ui/tabs.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ui/tabs.js b/ui/tabs.js index c45d6b3f6f7..e45a97c726c 100644 --- a/ui/tabs.js +++ b/ui/tabs.js @@ -372,7 +372,10 @@ return $.widget( "ui.tabs", { }, _processTabs: function() { - var that = this; + var that = this, + prevTabs = this.tabs, + prevAnchors = this.anchors, + prevPanels = this.panels; this.tablist = this._getList() .addClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" ) @@ -456,6 +459,13 @@ return $.widget( "ui.tabs", { this.panels .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ) .attr( "role", "tabpanel" ); + + // Avoid memory leaks (#10056) + if ( prevTabs ) { + this._off( prevTabs.not( this.tabs ) ); + this._off( prevAnchors.not( this.anchors ) ); + this._off( prevPanels.not( this.panels ) ); + } }, // allow overriding how to find the list for rare usage scenarios (#7715) From 4f98f4ad22fda3fe3b075ab8b4f5cf067137a9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 20 Aug 2014 16:04:54 -0400 Subject: [PATCH 3/3] Accordion: Avoid memory leak during refresh Ref #10056 --- ui/accordion.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ui/accordion.js b/ui/accordion.js index 5b748a3f22c..94643719731 100644 --- a/ui/accordion.js +++ b/ui/accordion.js @@ -259,13 +259,22 @@ return $.widget( "ui.accordion", { }, _processPanels: function() { + var prevHeaders = this.headers, + prevPanels = this.panels; + this.headers = this.element.find( this.options.header ) .addClass( "ui-accordion-header ui-state-default ui-corner-all" ); - this.headers.next() + this.panels = this.headers.next() .addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" ) .filter( ":not(.ui-accordion-content-active)" ) .hide(); + + // Avoid memory leaks (#10056) + if ( prevPanels ) { + this._off( prevHeaders.not( this.headers ) ); + this._off( prevPanels.not( this.panels ) ); + } }, _refresh: function() {