title: Copy array --> stack or heap overflow?
body: <p>I have an array named <code>globalArrayAllTrades</code> as you see below. I simply like to INVERT the date in a new copy of the array. So I loop through, create a new object and add it to the new array - simple.</p>
  
  <p>Then function does exactly as expected. BUT if the array contains too many objects the code fails with a "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory".</p>
  
  <p>My laptop has 8 GB of memory...When the NODEJS process crashes it uses about 1.5 GB and about 70% of of totally amount of available memory is used.</p>
  
  <p>I do run the NODEJS app with the parameter: <code>--max_old_space_size=5000</code> which normally fixes every thing. But not this one and i have tried MANY different ways to code the same function - BUT each and every time - it fails...unless the original array is smaller.</p>
  
  <p>How can I fix this issue? </p>
  
  <pre><code> function invertTrades(){
  
       var original = globalArrayAllTrades.slice();
  
       globalArrayAllTrades.length = 0;
       globalListAllTrades.length = 0;
  
       for(var i = 0; i &lt; original.length; i++){
  
           var objS = original[i];
           var objE = original[original.length-1-i];
           var objInv = new TradePoint(objS.number, objS.matchdate, objE.price, objE.size, objE.issell);
  
           globalArrayAllTrades.push(objInv);
  
           globalListAllTrades[objInv.matchdate] = objInv;
       }
   }
  </code></pre>