Had to make this an answer rather than a comment for length:
OK -- first a clarification of terms:
If it is running on a timer, then it is not recursive. It is a common misunderstanding, however.
It recursive code, a function calls itself -- the original function invocation remains on the stack until the whole thing finally unwinds and a value is returned to the original caller. When using a time out, each iteration of the function its in a separate execution context.
Recursive function example
function factorial(n) {
if (n == 1) {
return 1;
} else {
return n * factorial(n-1);
}
}
This is /not/ recursive:
function annoy() {
window.setTimeout(annoy, 1000);
window.alert("This will annoy every second!");
}
Each iteration of 'annoy' is completely independent and stand alone. It just sets up the timer for another instance to be called. There is no pile of 'annoy' functions on the stack and you can't return anything to the caller.
Secondly: In the example that I gave you, the variable a
not go out out of scope, but the old objects that a
refers to had no active references so they are free for release. What a variable points to can vary.
var a, b;
a = {};
b = a; // This object now has TWO references using it.
b = null; // The object now has one reference
a = null; // Object has no references and is free for release.
At this point, the best thing I can do is point you here:
http://www.ibm.com/developerworks/web/library/wa-sieve/