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 still exist and causing memory leak?
function myTest() {
var obj = document.createElement('div');
obj.addEventListener('click', function() {alert('whatever'); });
var body = document.getElementById('body'); // assume there is a <div id='body'></div> already
body.appendChild(obj);
}
// then after some user actions. I call this:
function emptyPage() {
var body = document.getElementById('body');
body.innerHTML = ''; //empty it.
}
So, the DOM object, <div> inside body is gone. But what about the eventlistener?
I'm just afraid that it will cause memory leak.