Kevin
Kevin

Reputation: 23634

Memory leak in inner function

(function(){
  var a;

  function inner1(arg){
    a = arg;
  }

  function inner2(){
    alert(a);
  }

})();

Will this cause memory leak in my application, since i am declaring variable a outside my other two inner functions.

Upvotes: 0

Views: 221

Answers (1)

Owen Allen
Owen Allen

Reputation: 11958

No, because you are declaring that variable inside an anonymous function closure already.

You can prove this by doing the following.

(function(){
  var a;

  function inner1(arg){
    a = arg;
  }

  function inner2(){
    alert(a);
  }

})();

alert(a)

Upvotes: 2

Related Questions