I am creating a single page application that will remain active and open for multiple days at a time in a browser. On this page I am displaying a timer in the top right corner. I have found however, that the way I am using the timer is leaking a small amount of memory.
https://jsfiddle.net/zbgonp84/
$(function(){
timer();
});
function timer(){
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
$("#timer").text(h + ":" + m + ":" + s);
var t = setTimeout(timer, 1000);
}
function checkTime(i) {
if (i < 10){
i = "0" + i;
}
return i;
}
I have recreated just the timer and the timer's div in a fiddle. If you open chrome's dev tools and record a time line, you can see that every second a new node is added to memory. If left for 24 hours, it will add a new node every second for the whole day and never gets collected.
I feel as if I am missing something fairly obvious as to why this is not being garbage collected, but what am I missing to unallocate the memory?