-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loop of console.log causes out of memory #3524
Comments
It's expected behavior: console.log is asynchronous, the memory associated with each call cannot be reclaimed until the next tick of the event loop. In your example that next tick never happens because of the infinite loop. If you rewrite your example to a callback-driven approach, it keeps running forever: let i = 0;
const next = () => process.stdout.write(`${i++}\n`, next);
next(); |
Thanks for the clarification, I had a lot of trouble to find wether |
That was a half-truth, it wasn't always synchronous. In v4.x it's always asynchronous except when stdio is redirected to file (which can block but normally won't.) |
I see, thank you for taking time to answer my questions ! |
This is in fact a duplicate of #1741. |
Any suggestion to work around this BUG? @bnoordhuis It is possible to write synchronous applications with modern Node.js? |
@litmit Node is an asynchronous I/O engine, with a bit of sync support in some places. If you read the issue @ChALkeR pointed you to, you would find at least one workaround: #1741 (comment) Or, you can write async code. |
@sam-github
work properly on Node v4 and crash on latest Node v6. PS. I known well that Node is an asynchronous I/O engine. But such simple thing like |
The other day, I went through something that I didn't understand in node.
When I do this, at a certain moment, my nodejs just stops printing stuff, giving me an output that looks like this
And after a while, I got this :
I was wondering, what can console.log do that could lead to an out of memory error ?
At first, I asked that question on stackoverflow, but someone suggested that I create an issue here, and I thought it could be a good idea.
What do you think about this ?
EDIT : Apparently, it has also be discussed here
The text was updated successfully, but these errors were encountered: