So, if in javascript I create a DOM object on an HTML page and attach an event listener to the DOM object, after removing the DOM from the HTML page, does the event listener still exist and cause a memory leak?
function myTest() { var obj = document.createElement('div'); obj.addEventListener('click', function() {alert('whatever'); }); var body = document.getElementById('body');
So, the DOM object, the <div> inside the body disappeared. But what about an eventlistener ? I am just afraid that this will cause a memory leak.
source share