node.js - nodejs setTimeout memory leak? -
v0.10.4
here's simple loop results in ever-increasing memory usage:
function redx(){ settimeout(function(){ redx() },1000); console.log('loop'); } redx();
what doing wrong ??
edit
ok, tried suggestion reference timeout object in scope , seems garbage collection kick in after 40 seconds, here's abbreviated logs top:
3941 root 20 0 32944 7284 4084 s 4.587 3.406 0:01.32 node
3941 root 20 0 32944 7460 4084 s 2.948 3.489 0:01.59 node
3941 root 20 0 32944 7516 4084 s 2.948 3.515 0:01.68 node
3941 root 20 0 33968 8400 4112 s 2.948 3.928 0:02.15 node
3941 root 20 0 33968 8920 4112 s 3.275 4.171 0:02.98 node
3941 root 20 0 33968 8964 4112 s 2.948 4.192 0:03.07 node
3941 root 20 0 33968 9212 4112 s 2.953 4.308 0:03.16 node
3941 root 20 0 33968 9212 4112 s 2.953 4.308 0:03.25 node
3941 root 20 0 33968 9212 4112 s 3.276 4.308 0:03.35 node
3941 root 20 0 33968 9212 4112 s 2.950 4.308 0:03.44 node
no idea why apparently if reference timeout object in scope of function nodejs garbage collect correctly.
function redx(){ var t = settimeout(function(){ redx() },50); console.log('hi'); } redx();
Comments
Post a Comment