ECMAscript does not have dynamic memory management. The garbage collector will take care of what requires memory in your script. Therefore, in fact, the question should be more similar,
"As the garbage collector knows, when it can free up memory for objects"
Simply put, most GCs look to see if there are any active links. This may be due to the parent context object, prototype chains, or any direct access to this object. In your particular case, setTimeout is executed at any time, it calls next() , which closes in the parent context .fade() , and the .face() function, in turn, closes the Effects function (context).
This means that as long as there are calls to setTimeout , the whole whole construct is stored in memory.
You can sometimes help older GC implementations by using null variable variables / references to them, which may collect some things sooner or in general, but modern implementations are pretty smart in that regard. In fact, you donβt have to worry about things like Live Object / Link.
jAndy Apr 11 '12 at 19:40 2012-04-11 19:40
source share