Javascript dynamic table memory usage

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-03-30T22:01:36Z Indexed on 2010/03/30 22:03 UTC
Read the original article Hit count: 132

Filed under:

I use a dynamic table:

<html>
<body>
<button id="button">Build table</button>
<div id="container">
<script type="text/javascript">
window.onload=function(){
 var table = null;

 var row = "<tr><td>111111111111111111111111111111111111111111111111111111</td>" +
           "<td>222222222222222222222222222222222222222222222222222222</td>" +
     "<td>333333333333333333333333333333333333333333333333333333</td></tr>";
 var data = null;
 for (var i = 0; i < 2000; i++){
  data += row;
 }

 var obj = document.getElementById("button");
 obj.onclick=function buildTable(){
  document.getElementById("container").innerHTML = "<div><table><tbody>" + data + "</tbody></table></div>";
 };
};
</script>
</body>
</html>

Using chromes task manager, each time new data is loaded the memory usage increases considerably and doesn't go down, so after some time the app consumes a lot of memory and requires the browser to be closed. Is there any change in the code I can use to solve this or is it a browser side problem?

© Stack Overflow or respective owner

Related posts about JavaScript