Does Remove A Dom Object (in Javascript) Will Cause Memory Leak If It Has Event Attached?
So, if in the javascript, I create a DOM object in the HTML page, and attach event listener to the DOM object, upon I remove the the DOM from HTML page, does the event listener sti
Solution 1:
The sad thing is, the W3C does not have an events collection where you can sift through all events applied to a single element. You could do it manually (i.e. obj.Events = {}; obj.Events[type] = []; obj.Events[type].push(fn) for each event that is added. Event[types] is an array so if you have multiple functions you wish to fire at a time, you can remove each individually), then loop through the obj.Events object to remove all events before removing the object.
Post a Comment for "Does Remove A Dom Object (in Javascript) Will Cause Memory Leak If It Has Event Attached?"