title: Why does writing to stdout in a hot loop cause an out of memory shutdown?
body: <pre><code>for (i = 0; i &lt; 3e11; i++) {
     process.stdout.write('aaaabbbbccccdddd') 
     process.stdout.write('\n') 
  }
  </code></pre>
  
  <p>Or this code:</p>
  
  <pre><code>for (i = 0; i &lt; 3e11; i++) {
     console.log('aaaabbbbccccdddd') 
  }
  </code></pre>
  
  <p>Just run in a terminal like this: <code>node test.js</code></p>
  
  <p>After about one minute produces this:</p>
  
  <pre><code>&lt;--- JS stacktrace ---&gt;
  Cannot get stack trace in GC.
  FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory
  Aborted (core dumped)
  </code></pre>
  
  <p>Where does it eat memory?</p>
  
  <pre><code>$ node -v
  v6.1.0
  </code></pre>