From 671f5a2ce21005090e0b69059799cd3dd1fbbf84 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Wed, 19 Aug 2015 20:06:09 -0400 Subject: [PATCH] Fix memory leak in AttachBody The `$dropdownContainer` variable wasn't being cleaned up when Select2 was destroyed, which was causing a memory leak. This closes https://github.com/select2/select2/issues/3559. This closes https://github.com/select2/select2/pull/3603. --- src/js/select2/dropdown/attachBody.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/js/select2/dropdown/attachBody.js b/src/js/select2/dropdown/attachBody.js index e1514edb..ece55417 100644 --- a/src/js/select2/dropdown/attachBody.js +++ b/src/js/select2/dropdown/attachBody.js @@ -44,6 +44,12 @@ define([ }); }; + AttachBody.prototype.destroy = function (decorated) { + decorated.call(this); + + this.$dropdownContainer.remove(); + }; + AttachBody.prototype.position = function (decorated, $dropdown, $container) { // Clone all of the container classes $dropdown.attr('class', $container.attr('class'));