<html>
<body>
<h1 id="t">Initial</h1>
<script>
var cnt=0;
setTimeout("addCounter()",100);
addCounter=function(){
++cnt;
if (cnt>1000000) cnt=0;
document.getElementById('t').firstChild.nodeValue='Counter: #'+(cnt);
setTimeout("addCounter()",100);
}
</script>
</body>
</html>
When I run this sample code in Internet Explorer/Firefox/Chrome, the memory usage increases until the browser/os runs out of memory and the browser crashes!
Any one can help me to rewrite the code that not wast memory? Or I have report it as a bug for browser developer?
After I increased memory of test machine, I found that after a while the memory usage did not increase any more! It seem the garbage collector (or any thing that is responsible for real free unused memory) is not optimized for low memory systems (like which one I used im my first tests)
In fact Chrome after spending about 50M is ok now, IE 9 after 30M. and I did not check FF yet!