Example of Google's Closure Compiler eliminating the memory leak:
var theThing = null;
function replaceThing() {
theThing = {
longStr: Array(1E6).join("*"),
someMethod: function() { }
};
}
setInterval(replaceThing, 1E3);
http://closure-compiler.appspot.com/home
For a more detailed explanation, check out the post that I lifted this example from: http://point.davidglasser.net/2013/06/27/surprising-javascri...