0

In Javascript, does the following create a memory leak

var button = document.createElement("input");
button.setAttribute("type","button");
button.addEventListener("click", myFunction);
button = null;

Do I have to remove the event listener first?

EDIT

Update to my question, I think that because I'm not actually adding this element to the DOM, then it's not a duplicate?

MyDaftQuestions
  • 4,487
  • 17
  • 63
  • 120
  • @Amadan, Please see the edit. Unless my understanding is incorrect, I've not added this element to the DOM. The element exists in memory only (I think) – MyDaftQuestions Dec 02 '15 at 07:32
  • Whether or not you add it to the DOM is not an issue; whether you still hold the reference to the element or not is. – Amadan Dec 02 '15 at 07:44

0 Answers0