
DOM nodes do not clear after remove(). Is there a memory leak? - jikuri
We have noticed huge DOM Nodes count and memory increase on our Angular app and in our effort to debug it we stripped down everything. In the end, we were left with the following pure html and javascript code which demonstrates the problem.<p>Please follow through the following simple code snippet.<p>&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
    &lt;head&gt;
    &lt;&#x2F;head&gt;&lt;body&gt;&lt;&#x2F;body&gt;&lt;&#x2F;html&gt;
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.<p>Let&#x27;s just add an &lt;input&gt; like this:<p>&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
    &lt;head&gt;
    &lt;&#x2F;head&gt;&lt;body&gt;&lt;input&gt;&lt;&#x2F;body&gt;&lt;&#x2F;html&gt;
Reload the snippet on a new tab and count the DOM Nodes, it should be 9.<p>Then, run this in the console to remove the &lt;input&gt;<p>document.getElementsByTagName(&#x27;input&#x27;)[0].remove()
The count should be 6, which is as expected.<p>Finally, reload the snipped on a new tab again. Make sure the DOM Nodes show 9 and then type some text in the &lt;input&gt; 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.<p>Now let&#x27;s remove the &lt;input&gt; as before with:<p>document.getElementsByTagName(&#x27;input&#x27;)[0].remove()
See the DOM Nodes, they are still 10 as if nothing was removed.<p>Any thoughts?
======
phillipseamore
Nodes aren't cleared until the next GC cycle.

~~~
gus_massa
Not the OP, but the next question is: Can you force the GC to run?

Perhaps this can be useful:
[https://stackoverflow.com/questions/13950394/forcing-
garbage...](https://stackoverflow.com/questions/13950394/forcing-garbage-
collection-in-google-chrome)

------
oregontechninja
Lol, wrong site. You might get an answer but try stack overflow or something
similar. Hope that helps..

