Javascript dynamic table memory usage
- by Dan
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?