Remove event listeners - memory leak #5270
Description
Had memory leak on removing elements from the dom (switching views, ng-switch ...)
Solved it partially by tweaking jqlite implementation.
When jqlite remove event listeners it passes wrong function reference
(not the same it passed on add listener).
Actually it try to pass array of functions - so it doesn't remove it properly.
https://github.com/angular/angular.js/blob/master/src/jqLite.js#L218
https://github.com/angular/angular.js/blob/master/src/jqLite.js#L224
To fix it I replaced it with actual handler that was added:
removeEventListenerFn(element, type, handle);
It is very easy to check by breakpoints these lines..
https://github.com/angular/angular.js/blob/master/src/jqLite.js#L652
eventHandler.elem = element;
Why we need additional reference to the element for the handler function.
As I can see it never used ...
Maybe it's safe to delete this line.
Now app consume less memory and event listeners released properly.
But I still see growing number of dom elements...
Looks like on removing it from the dom it still have some references unreleased...