开发者

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

开发者 https://www.devze.com 2023-02-11 10:56 出处:网络
If I have a self-destroying function function tempFunc() { //do some stuff, then... tempFunc = function() {return;}

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

精彩评论

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