You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
I had a lot of trouble to find wether console.log was sync or async (for example this post says that Starting with Node 0.6 [...] stdout is synchronous now.
Starting with Node 0.6 [...] stdout is synchronous now.
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.)
Any suggestion to work around this BUG?
I'm using Node for small console app. No asynchronous code at all.
For debug purposes i'm always using console.log().
All working well in node v4.8.0 but crashes in node v6.x with message FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
@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)
Activity
bnoordhuis commentedon Oct 26, 2015
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:
tforgione commentedon Oct 26, 2015
Thanks for the clarification,
I had a lot of trouble to find wether
console.logwas sync or async (for example this post says that Starting with Node 0.6 [...] stdout is synchronous now.bnoordhuis commentedon Oct 26, 2015
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.)
tforgione commentedon Oct 26, 2015
I see, thank you for taking time to answer my questions !
ChALkeR commentedon Nov 2, 2015
This is in fact a duplicate of #1741.
litmit commentedon Feb 26, 2017
Any suggestion to work around this BUG?
I'm using Node for small console app. No asynchronous code at all.
For debug purposes i'm always using
console.log().All working well in node v4.8.0 but crashes in node v6.x with message
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory@bnoordhuis It is possible to write synchronous applications with modern Node.js?
sam-github commentedon Feb 28, 2017
@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.
litmit commentedon Mar 1, 2017
@sam-github
As decribed by @Fishrock123 in comments to #11568 the console should be synchronous when stdout redirected to a file.
But
work properly on Node v4 and crash on latest Node v6.
Currently I'm using console-sync as workaround.
PS. I known well that Node is an asynchronous I/O engine. But such simple thing like
consoleshould just work in any case (IMHO of course).