Fix slow memory leak caused by not clearing cache#5965
Merged
kevin-brown merged 1 commit intodevelopfrom Jan 8, 2021
Merged
Conversation
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.
anttikuuskoski
pushed a commit
to anttikuuskoski/select2
that referenced
this pull request
Mar 29, 2022
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request includes a
The following changes were made
If this is related to an existing ticket, include a link to it as well.
Fixes #5912