浏览代码

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 年之前
父节点
当前提交
671f5a2ce2
共有 1 个文件被更改,包括 6 次插入0 次删除
  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'));