nodejs setTimeout memory leak?

后端 未结 2 1810
有刺的猬
有刺的猬 2021-02-04 13:07

v0.10.4

Here\'s the simple loop that results in an ever-increasing memory usage:

function redx(){
      setTimeout(function(){ redx() },1000);
      cons         


        
2条回答
  •  盖世英雄少女心
    2021-02-04 13:23

    No idea why but apparently if you reference the timeout object in the scope of the function nodejs will do the garbage collect that correctly.

    function redx(){
          var t = setTimeout(function(){ redx() },50);
          console.log('hi');
    }
    
    redx();
    

提交回复
热议问题