Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating DOM via Javascript causing memory leaks (only in Firefox?)
    primarykey
    data
    text
    <p>I know this question has been asked before, but none of the answers seem to resolve the issue. I'm testing an AJAX webpage which updates elements in the DOM via javascript. </p> <p>Every minute, the server is queried for new data and the DOM is updated accordingly. From what I can tell, the memory usage for this page in Chrome grows, but not too much (it starts around 40 MB and reaches maybe 80 MB max). In Firefox, however, the memory usage starts around 120 MB and can expand to over 400 MB. I've stepped through the Javascript with Firebug and it seems like the memory expands the most when the DOM is updated via my Javascript methods.</p> <p>The DOM manipulation is simple, such as:</p> <pre><code>var myTable = document.createElement("table"); var thead = document.createElement("thead"); var tr = document.createElement("tr"); var th = document.createElement("th"); th.appendChild(document.createTextNode("column1")); tr.appendChild(th); for(var test in obj.testObjs){ th = document.createElement("th"); th.appendChild(document.createTextNode(obj.testObjs[test].myVar)); tr.appendChild(th); } </code></pre> <p>Before appending new data to the nodes in the DOM, I first clear the existing data. I've tried a number of ways, including what is described here: <a href="https://stackoverflow.com/questions/3785258/how-to-remove-dom-elements-without-memory-leaks">How to remove DOM elements without memory leaks?</a></p> <p>As well as a simple way such as:</p> <pre><code>function clearChildren(node){ if(node != null){ while (node.hasChildNodes()) node.removeChild(node.firstChild); } } </code></pre> <p>I've also read ( <a href="https://stackoverflow.com/questions/3750797/cyclic-adding-removing-of-dom-nodes-causes-memory-leaks-in-javascript">Cyclic adding/removing of DOM nodes causes memory leaks in JavaScript?</a> ) that browsers only start collecting garbage when it reaches a certain level? Can that be confirmed? I feel that my PC is running sluggish after a while due to the growing memory.</p> <p>I feel there has to be a solution to this, because commercial sites I've tested that perform the same functional steps do not cause memory usage to grow.</p> <p>Any help would be greatly appreciated.</p> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload