according to mdn documentation the method removeChild removes a node from the DOM but it still resides in memory.
My problem is that I want to delete it from memory as well.
I’ve tried with the delete operator but the object is still there…
myCanvas.parentElement.removeChild(myCanvas); // myCanvas actually removed from DOM
delete myCanvas; // false. does nothing
alert(myCanvas); // shows HTMLCanvasElement instead of undefined
Read http://perfectionkills.com/understanding-delete/. The delete operator is not for variables (that’s why it returns
false).If you want to remove the variable’s reference to the DOM node, use
to overwrite the value. Usually you never need to do this, because the garbage collector of JS does all the work for you.