DOM nodes do not clear after remove(). Is there a memory leak?
Please follow through the following simple code snippet.
<!DOCTYPE HTML> <html> <head> </head><body></body></html> Load this snippet on Chrome and open up the Chrome Performance monitor, click on the Collect garbage icon and see the DOM Nodes counter. It should be 6.
Let's just add an <input> like this:
<!DOCTYPE HTML> <html> <head> </head><body><input></body></html> Reload the snippet on a new tab and count the DOM Nodes, it should be 9.
Then, run this in the console to remove the <input>
document.getElementsByTagName('input')[0].remove() The count should be 6, which is as expected.
Finally, reload the snipped on a new tab again. Make sure the DOM Nodes show 9 and then type some text in the <input> field. You will notice that DOM Nodes increase by one, reaching 10, this is the entered #text that is added into the DOM tree. So far so good.
Now let's remove the <input> as before with:
document.getElementsByTagName('input')[0].remove() See the DOM Nodes, they are still 10 as if nothing was removed.
Any thoughts?
4 comments
[ 5.1 ms ] story [ 20.1 ms ] threadPerhaps this can be useful: https://stackoverflow.com/questions/13950394/forcing-garbage...