title: Recursion - Node out of memory
body: <p>When I run the following code 9999999+ times, Node returns with:</p>
  
  <pre><code>FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
  Aborted (core dumped)
  </code></pre>
  
  <p>Whats the best solution to get around this issue, other than increasing the max alloc size or any command line arguments?</p>
  
  <p>I'd like to improve the code quality rather than hack a solution.</p>
  
  <p>The following is the main bulk of recursion within the application.</p>
  
  <p>The application is a load testing tool.</p>
  
  <pre><code>a.prototype.createClients = function(){
      for(var i = 0; i &lt; 999999999; i++){
          this.recursiveRequest();
      }
  }
  
  a.prototype.recursiveRequest = function(){
      var self    =   this;
      self.hrtime =   process.hrtime();
  
      if(!this.halt){
          self.reqMade++;
  
          this.http.get(this.options, function(resp){
              resp.on('data', function(){})
                  .on("connection", function(){
                  })
                  .on("end", function(){
                      self.onSuccess();
                  });
          })
              .on("error", function(e){
                  self.onError();
              });
      }
  }
  
  a.prototype.onSuccess = function(){
      var elapsed     =   process.hrtime(this.hrtime),
          ms          =   elapsed[0] * 1000000 + elapsed[1] / 1000
  
          this.times.push(ms);
          this.successful++;
          this.recursiveRequest();
  }
  </code></pre>