Here's some code that I run on Google Chrome 19.0.1061.1 (Official Build 125213) dev:
<html>
<title>Memory Leak</title>
<script type="text/javascript">
(function(){
this.window.setInterval(function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', '', false);
xhr.send();
}, 50);
}).call(this);
</script>
</html>
When I inspect memory usage in chrome://tasks, I can see that "Private Memory" is growing up indefinitely (8GB RAM config). If I change the sample of code above to something like that:
<html>
<title>Memory Leak</title>
<script type="text/javascript">
(function(){
var xhr = new XMLHttpRequest();
var timeout = this.window.setInterval(function() {
xhr.open('GET', '', false);
xhr.send();
}, 50);
}).call(this);
</script>
</html>
It's now OK.
I don't get it. Why keeping a reference to the setInterval function helps and why defining only one xhr helps since previous declaration was in a closure? Is it related only to v8?
I would appreciate your insights on it.