As already mentioned, when a function exits, your variable goes out of scope, since the scope is only inside the function, so gc can clear it.
But it is possible that this variable can be referenced by something outside the function, then it will not be displayed for some time, if at all, since it still has a link to it.
You might want to read the review in javascript: http://www.webdotdev.com/nvd/content/view/1340/
With closure, you can create a memory leak, which may be the problem you are trying to deal with, and is related to the problem I was talking about: http://www.jibbering.com/faq/faq_notes/closures.html
source share