开发者

What happens to the memory used by a function when it is removed

If I have a self-destroying function

function tempFunc() {
   //do some stuff, then...

   tempFunc = function() {return;}
}

or

function tempFunc() {
   //do some stuff, then...

   delete tempFunc;
}

What happens to the origin开发者_运维百科al code of tempFunc? Is it held in memory anywhere? How is the situation changed if the function leaves behind something a bit more permanent e.g. creates an object which has access to variables contained within the function's closure.


When there are no more referenced to the function, it can be garbage-collected.

If there are referenced through closures, it can't.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜