recently I have read articles about garbage collection mechanism and closures, but I still don"t have a deep understanding of them, and there are some doubts. I hope some bosses can give me an answer
.my understanding is that local variables are recycled after the function is executed, while global variables are not recycled until the window closes (because of the life cycle of global variables? )
so will the function declaration be recycled? Recycle only variables? The following example:
function a(){
var i = 1;
function b(){
return i
}
return b
}
var x = a();
x()
after executing x (), the function an and the internal variables I and b will be recycled?
Another function ofclosures is to reside in memory, for example:
for(var i = 0; i< 9; iPP){
(function(i){
setTimeout(function(){
console.log(i)
},1000)
})(i)
}
this example is to save the variable I in an anonymous function, so will I be recycled after the function is executed?