It wouldn't make any difference setting a local variable to null
at the end of the function because it would be removed from the stack when it returns anyway.
However, inside of a closure, the variable will not be deallocated.
var fn = function() {
var local = 0;
return function() {
console.log(++local);
}
}
var returned = fn();
returned(); // 1
returned(); // 2
jsFiddle.
When the inner function is returned, the outer variable's scope will live on, accessible to the returned inner function.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…