1
function fn(args){
    var a= 'something';
    doSomething('dummy',function(){

    });
}

fn();

In this code, is anonymous callback become closure or just exit after execution? If it become become a closure, how can i get back memory because it always has access to fn's activation object.

Thant Sin Aung
  • 682
  • 2
  • 10
  • 20

1 Answers1

1

It will only be a closure if the lambda uses the enclosing functions'(fn) local variables or parameter, e.g. a or args.

Re: Memory recovery - Don't worry about it* - the GC will know when references are no longer reachable and collect them (whether they are used in closures or not). See also here.

* Don't worry too much

Community
  • 1
  • 1
StuartLC
  • 104,537
  • 17
  • 209
  • 285
  • If i use `fn` local variables or `arguments`, it will be closure.So, i m creating closure every time when i call `fn` & how can I clean the scope after callback was execute to get back memory. – Thant Sin Aung Dec 19 '14 at 22:07