5 ms·
>You called addEventListener but forgot to call removeEventListener. Shouldn't this be handled by the browser gc? If the element isn't in the DOM and there are
by Matheus28 5y ago
>You called addEventListener but forgot to call removeEventListener.
Shouldn't this be handled by the browser gc? If the element isn't in the DOM and there aren't any js references left anymore
- nolanl 5y agoIt depends. For elements that are removed from the DOM, then yes, the event listener should also be automatically removed: https://jakearchibald.com/2020/events-and-gc/ https://jakearchibald.com/2020/events-and-gc/ However, if you're adding event listeners to the document, the window, or some permanent element (header, footer, etc.), then those won't be GC'ed since the DOM node is never GC'ed.