Browse Source

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.
Kevin Brown 9 năm trước cách đây
mục cha
commit
671f5a2ce2
1 tập tin đã thay đổi với 6 bổ sung0 xóa
  1. 6 0
      src/js/select2/dropdown/attachBody.js

+ 6 - 0
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'));