浏览代码

Fix slow memory leak caused by not clearing cache (#5965)

There was a very slow memory leak that can occur if you were creating
and destroying many Select2 elements on a single page. This was caused
by the internal Select2 cache not being cleared for the container
element, causing a reference to it to be left in memory even after
the Select2 element was destroyed.

The memory was put in place to make it easier to destroy a Select2
element after it is initialized, specifically when the user clicks
off of the Select2 element. Because some pages run with multiple
versions of Select2 and jQuery at the same time, we specifically
cache a local copy of the jQuery element to allow it to be
deconflicted at the time of the call. This cached locally copy was
not being properly cleared when Select2 was being destroyed though,
which had the (very small) potential to cause a memory leak over time.
Kevin Brown 4 年之前
父节点
当前提交
0de98d9999
共有 1 个文件被更改,包括 1 次插入0 次删除
  1. 1 0
      src/js/select2/core.js

+ 1 - 0
src/js/select2/core.js

@@ -554,6 +554,7 @@ define([
   };
 
   Select2.prototype.destroy = function () {
+    Utils.RemoveData(this.$container[0]);
     this.$container.remove();
 
     this._observer.disconnect();