ember-select-2 icon indicating copy to clipboard operation
ember-select-2 copied to clipboard

[Memory leak] Select2 plugin is not properly detached

Open cibernox opened this issue 8 years ago • 4 comments

This is only a problem in testing (but a big one, since our test suite uses 4GB+ of ram because of this).

My main suspect is that when the select2 plugin is initialized, it adds some sort of event handler to the body of the document. At the same time, some action handler grabs a reference to the component (this) and that holds a reference to the container, the application and the entire world, so the app is never garbage collected, leading to an outstanding memory consumption in tests, enough to break the CI.

I suspect that this could be fixed by setting handlers in the application root, that in testing is not the body but a div named #ember-testing.

cibernox avatar Aug 07 '15 10:08 cibernox

I can see that this is a problem. The component itself tries to destroy the select2 component in the willDestroyElement callback. I will gladly merge a fix if you can come up with one, I unfortunately really have no time at all at the moment to look into this :( (as you can see by the other issues piling up, sorry!)

iStefo avatar Aug 07 '15 11:08 iStefo

Hi, we got into this too, I tried to find out where memory leaks were coming from in our specs (this is quite annoying as the webkit_server process grows to several GB or ram. I also found a memory leak in favico.js but this one I could easily avoid by disabling favico.js in test, for select2 I can't really disable it in specs as I'm using it's features. In my case we're instantiating two small select2 per page and it leaks about 20M of memory each time.

Do you see any way at least to workaround this by destroying the objects manually at the end of each test ?

jarthod avatar May 10 '16 15:05 jarthod

any update?

kntmrkm avatar Jul 11 '16 18:07 kntmrkm

@kntmrkm For completeness, I created Ember Power Select to have a select component that doesn't rely on any jquery plugin, and the default UI is almost identical to select2.

cibernox avatar Jul 11 '16 20:07 cibernox