I am trying to run the following node script:
var request = require('request');
var async = require('async');
var util = require('util');
function makeRequest(dom, cb) {
request("http://" + dom,
function(err, response, body) {
console.log(util.inspect(process.memoryUsage()));
cb();
});
}
var arr = [];
for (var i = 0; i < 1600000; i++) {
arr.push("google.com");
}
async.eachLimit(arr, 100, function(dom, call) {
process.nextTick(function() {
makeRequest(dom, call);
});
}, function(err) {
console.log("done");
});
function call() {
}
I'm basically making a lot of HTTP requests to a web service (I used google.com for example's sake). The problem is the script's memory usage just steadily increases without backing down up until the point it crashes with a "FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory". Can anyone please tell me why the memory leak occurs and how I can fix it? Thank you.