Memory Leak: `material_select` never removes global `click` handlers
See original GitHub issueDescription
$.material_select
installs multiple global click
handlers on window
, but never cleans them up:
This results in a memory leak in single-page applications that call this function when rendering a view. Every time the function is called, new global click handlers are added. Since they are never removed, the browser cannot garbage collect the handler or any data within its closure (which includes DOM NodeList
s within jQuery objects).
Is there a way to either avoid a global click handler, to only install a single global click handler, or to clean up global click handlers at some point?
Repro Steps
N/A
Screenshots / Codepen
N/A
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
javascript memory leak when DOM element deleted, what kind ...
The Foo variable to store your instance is global, and Foo.child is still a globally accessible reference. But even you didn't store the ......
Read more >Are you afraid of event handlers because of C# memory leak ...
The answer is, No, I mean, not always. But, please note. I did not say 'Never.' I said, 'Not always.' That means, yes,...
Read more >Causes of Memory Leaks in JavaScript and How to Avoid Them
Common Sources of Memory Leaks in JavaScript Code # · 1. Accidental global variables · 2. Closures · 3. Timers · 4. Event...
Read more >How to fix the React memory leak warning - DEV Community
Global variables are never garbage collected so don't forget to remove event handlers manually if the event emitter is stored in a global...
Read more >Righting Web Development - ScholarWorks@UMass Amherst
BLeak is the first system for automatically debugging memory leaks ... [137] Vilk, John. Memory Leak: material select never removes global click handlers....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jvilk
the lifecycle of SPA’s are beyond the scope of jQuery plugins. one approach you might take is to override jQuery’s
init()
method and use it to maintain a list of selectors with bound events, and use the well known hack to remove all events.override
$.fn.init
:remove events when needed:
you could probably take it a bit further and remove from specific selectors, but i’ll leave that exercise up to you.
@r3wt thanks! 😄