Angular Memory Leaks 2 - Steps
Demonstrates a 'steps' memory usage timeline.
by Dave Kerr
HTML
<h3>Steps</h3>
<p>Demonstrates a 'steps' pattern of memory usage. We'll occasionally allocate large chunks of memory, but never free it.</p>
<button id="start">Start</button>
JavaScript
document.getElementById("start").onclick = function() {
window.data = [];
window.setInterval(function() {
// Create an array of zeros, pin it to a GC root.
var count = (Math.random() * 10000) + 500;
var numbers = [];
for(var i=0; i<count; i++)
numbers[i] = 0;
window.data.push(numbers);
}, 1000);
};