Closed
Description
Sorry if it is a dumb question/issue, but why does this code:
for (i = 0; i < 1000000; i++) {
console.log('abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc' + i);
}
hang node
for a few seconds (at around i = 1500) before resuming again? During the hang the amount of memory used by the node
process increases very fast and the CPU usage is very high during that time.
On the other hand, if I write:
for (i = 0; i < 1000000; i++) {
console.log(i);
}
then the node
process does not hang at all.
The reason I am asking is that I have a piece of code which involves printing inside a loop, and it also hangs, but for much longer (like 30-60 seconds, before resuming again). The code prints the paths of all files in a directory (walking recursively): https://gist.github.com/pgkos/f0a650daf56aa49899e9.
The issue occurs on both io.js v2.0.2 and node.js v0.12.2, on Ubuntu 64-bit.