| console.log memory leak ? | Filirom1 | 4/10/12 7:43 AM | Hi, I am struggling to understand why NodeJs do not decrease the resident memory after a lot of console.log. If someone could explain me this behaviour I would be very happy.
for (var i = 0; i< 100 * 1000; i++){ console.log(i); } setTimeout(function(){ console.log('END') }, 10000000); The last setTimeout is used to keep nodejs running, so gc happens when node is idle. The ouput is the following: $ while true; do sleep 1; cat /proc/`pgrep node`/status |grep RSS; done &
$ node --trace_gc log.js ... 99998 99999 VmRSS: 88808 kB VmRSS: 88808 kB
VmRSS: 88808 kB VmRSS: 88808 kB VmRSS: 88808 kB
Mark-sweep 39.5 -> 2.4 MB, 3 / 37 ms. VmRSS: 57120 kB Mark-compact 2.4 -> 1.9 MB, 24 ms. Mark-compact 1.9 -> 1.9 MB, 8 ms.
VmRSS: 30344 kB VmRSS: 30344 kB VmRSS: 30344 kB
If I only do 1000 iterations (instead of 100 000), the final VmRSS (after gc) is less important: ... 998 999 VmRSS: 12084 kB
VmRSS: 12084 kB VmRSS: 12084 kB VmRSS: 12084 kB
VmRSS: 12084 kB Scavenge 2.4 -> 2.2 MB, 0 ms. Mark-sweep 2.2 -> 1.9 MB, 4 ms. Mark-compact 1.9 -> 1.9 MB, 15 ms.
VmRSS: 9468 kB VmRSS: 9468 kB This thread is cross posted in stack overflow : http://stackoverflow.com/questions/8856892/node-js-file-memory-leak |
| Re: [nodejs] console.log memory leak ? | Ben Noordhuis | 4/10/12 7:57 AM | On Tue, Apr 10, 2012 at 16:43, Romain <fili...@gmail.com> wrote: This question has been asked in various forms on both the mailing list Each console.log() statement allocates some memory that is not |
| Re: [nodejs] console.log memory leak ? | Filirom1 | 4/10/12 8:54 AM | Memory increase it's ok. But I was thinking that the memory allocated by all the console.log would be free after 5 minutes of idle time. I don't understand why I need to segment the loop, if I wait a very long time after the loop.
2012/4/10 Ben Noordhuis <in...@bnoordhuis.nl>
|
| Re: [nodejs] console.log memory leak ? | Ben Noordhuis | 4/10/12 9:17 AM | On Tue, Apr 10, 2012 at 17:54, Romain <fili...@gmail.com> wrote: Oh, that's another thing: RSS doesn't work like that. free()ing memory The bottom line is that RSS is not a very reliable metric for |
| Re: [nodejs] console.log memory leak ? | Filirom1 | 4/10/12 11:41 AM | Many thanks, it's exactly what I was looking for. |