Understanding javascript closures and memory usage

后端 未结 2 1808
迷失自我
迷失自我 2021-02-01 23:35

EDIT: This is just a simple example to demontrate the concern I have with a much larger program. I wouldn\'t use this actual code for anything :)

If I r

2条回答
  •  心在旅途
    2021-02-02 00:05

    A new closure is created every time the timeout callback is called, as you correctly say. But once the callback has been executed, there is no longer anything referencing the previous closure, so it can be garbage collected.

提交回复
热议问题