Answer the question
In order to leave comments, you need to log in
How to avoid memory leak in nodejs?
I am writing a spider on nodejs, I am faced with the fact that it constantly eats more and more memory. I tried to make it as simple as possible, this is what happened:
var humanize = require('humanize')
, request = require('request');
function fetch(url, c) {
request(url, function(err, resp, body) {
if (err) {
c(err);
return;
}
c(err, resp, body)
});
}
function callback(err, resp, body) {
var memory = process.memoryUsage();
console.log("Memory usage: " + humanize.filesize(memory.heapUsed) + " / " + humanize.filesize(memory.heapTotal));
fetch('http://google.com', callback);
}
fetch('http://google.com', callback);
Answer the question
In order to leave comments, you need to log in
habrahabr.ru/post/123154
read paragraph
node --nouse-idle-notification --expose-gc server.js
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question