I understand that code in closure can access variables & methods & arguments up the scope chain, but what happens if it doesn't use any of them ? do those variables still retained ?
Consider this case :
function f(){
var a=[];
for(var i=0;i<1000000;i++) a.push({});
return function(){
alert('Hi');
};
}
var x = f();
Does variable a
retained in memory even though the closure does not use it ?
Thanks
UPDATE: Seems there's no answer about 'trivial' closures. So is it fair to assume that each and every closure ( even if it does nothing at all ) may retain in memory all the methods up the scope chain including their arguments , variables and inner functions ( until the closure is garbage collected )?
Also, about the 'possibly duplicate' question about node.js - to my knowledge node.js runs only on a dedicated environment that based on google's v8 JS engine. Here I'm talking about web-apps that will run in any modern browser ( in most cases )