IE memory leak in setInterval
On IE10 setInterval does not seem to free the function after the interval has been cleared. In the test code, the closure of the function contains big data - the function is not referenced anymore by code after the interval was cleared, however the Memory usage stays high. using setTimeout the problem does not seem to exist. Also other browsers seem to work correctly.
by yGuy
HTML
<body onLoad="start()">
</body>
JavaScript
(function(){
var _setTimeout = window.setTimeout;
var _clearTimeout = window.clearTimeout;
window.setInterval = function(fn, interval){
var recurse = function(){
var newId = _setTimeout(recurse, interval);
window.setInterval.mapping[returnValue] = newId;
fn();
}
var id = _setTimeout(recurse, interval);
var returnValue = id;
while (window.setInterval.mapping[returnValue]){
returnValue++;
}
window.setInterval.mapping[returnValue] = id;
return returnValue;
}
window.setInterval.mapping = {};
window.clearInterval = function(id){
var realId = window.setInterval.mapping[id];
_clearTimeout(realId);
delete window.setInterval.mapping[id];
}
var loops = 1000;
window.start = function() {
for (var i = 0; i < loops; i++){
doIntervalStuff();
}
}
var doIntervalStuff = function() {
var a = null;
var intervalId = setInterval(function() {
a = createBigArray();
clearInterval(intervalId);
loops--
if (loops == 0) document.body.innerHTML = "Done - check Memory usage!";
}, 100);
}
var createBigArray = function() {
var arraySize=5000;
var a = new Array();
for(var i=0; i<arraySize; i++) {
a.push("dummy string"+i);
}
return a;
}
})();