24 ms·
I think there's a reason why events are not mentioned in your linked document... The reference is maintained in memory because the browser has no idea if you wi
by syspec 4y ago
I think there's a reason why events are not mentioned in your linked document... The reference is maintained in memory because the browser has no idea if you will be using it again. After creating the listener, you may very well append it to another element later for all the browser knows.
Also the browser doesn't make a distinction to the type of event (such as `click` ), and say "Oh well you can't click on an element not in the DOM, I think I can clean this up"
So no it will not clean it up and it will leak memory, see for yourself
- grabanski 4y agoHere's what I came up with for switching to event delegation: https://github.com/1Marc/todomvc-vanillajs-2022/blob/event-delgation/js/app.js#L51-L78 https://github.com/1Marc/todomvc-vanillajs-2022/blob/event-d...