When actually is a closure created?

后端 未结 5 875
谎友^
谎友^ 2021-02-04 08:37

Is it true that a closure is created in the following cases for foo, but not for bar?

Case 1:



        
5条回答
  •  名媛妹妹
    2021-02-04 08:53

    closure bar will exist until foo returns, and the closure bar will then be garbage collected, since there is no reference to it at all anywhere

    Yes.

提交回复
热议问题