Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak when the dropdown is opened #2566

Closed
wants to merge 1 commit into from

Conversation

akkumanova
Copy link

Description

This pull request fixes a memory leak in select2 which is caused by the event handler (link to code) on the dropdown mask, which once created is never destroyed.
After opening the select2, the above event handler is registered. The problem is that it references the parent context of the opening function, so that context is never released. And the that variable (which holds the this) is promoted to the context because it is referenced in this closure. This kind of memory leak is described in more detail here and here.

I've reproduced the leak in this plunker (direct link), where after opening the select2 and destroying it there is still a reference to BigObject, which is held by the event handler:

The heap snapshot was taken using Chrome 36 in incognito mode.

Solution

The memory leak is fixed by creating the event handler in a separate function. This plunker (direct link) is using the fixed version of the code, so you can see that everything is OK.

@georgiyordanov
Copy link

@kevin-brown any remarks on this issue?

@kevin-brown
Copy link
Member

Now that 4.0.0 has been released, the branches have switched and this is pointing to the wrong one. If you are still interested in getting this merged, create a new pull request for the stable/3.5 branch and link back to this old one.

Until then, we have to close this off as it is not possible to merge it in.

@kevin-brown kevin-brown closed this May 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants