Serious memory leak
Ellisthion opened this issue · comments
Due to a questionable feature in jQuery, the resize code causes a memory leak where it will hold on to every DOM node it has ever tracked. In a single-page application this can be a serious issue if you're creating and destroying things around the place.
jQuery has a strange feature where it keeps references to every state in a series of jQuery method calls, in a property called prevObject
. If you keep jQuery references around for a while and do lots of stuff, they can amass a huge chain of prevObject
references, preventing anything from being garbage collected. More information: http://blog.cowchimp.com/jquery-prevobject-memory-leak/
This resize library stores its tracked elements in a jQuery array (var elems = $([])
), which is never disposed. It then uses mutating functions to add and remove elements. Unfortunately, due to the above jQuery feature, this means that any element that ever enters that elems
collection will be retained indefinitely.
The solution is to replace the elems
jQuery array with a normal Javascript array.
I was just looking through forks of this library to see if anybody has fixed this and found this commit.
@meze, will you open a PR to this library?