Skip to content

Instantly share code, notes, and snippets.

@FrankGrimm
Created November 9, 2010 16:43
Show Gist options
  • Save FrankGrimm/669352 to your computer and use it in GitHub Desktop.
Save FrankGrimm/669352 to your computer and use it in GitHub Desktop.
var http = require('http');
var requestCounter = 0;
var startedRequests = 0;
var endedRequests = 0;
http.createServer(function (request, response) {
request.number = requestCounter++;
console.log("#" + request.number + " started");
startedRequests++;
request.on('end', function() {
console.log("#" + request.number + " ended");
endedRequests++;
});
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hi there\n');
}).listen(8080);
setInterval(function() {
console.log("[TOTAL] " + requestCounter + " [S] " + startedRequests + " [E] " + endedRequests + " [S-E] " + (startedRequests - endedRequests));
}, 1000);
@gotys
Copy link

gotys commented Nov 9, 2010

The following code will cause memory leaks. Can this be avoided?

var http = require('http');

var requestCounter = 0;
var startedRequests = 0;
var endedRequests = 0;

http.createServer(function (request, response) {
request.number = requestCounter++;

request.connection.workload = 'x';
for (var i=0; i<1000000; i++) {request.connection.workload+='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';}

console.log("#" + request.number + " started");

startedRequests++;

request.on('end', function() {
  console.log("#" + request.number + " ended");
  endedRequests++;
});

response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hi there\n');

}).listen(8008,'192.168.2.95');

setInterval(function() {
console.log("[TOTAL] " + requestCounter + " [S] " + startedRequests + " [E] " + endedRequests + " [S-E] " + (startedRequests - endedRequests));
}, 1000);

@FrankGrimm
Copy link
Author

Can't reproduce it with that code either, sorry. Resident memory size goes down again after the GC cleaned up on unused objects here and connections are ended correct. Maybe ask the mailing list if anybody else notices that problem.

@gotys
Copy link

gotys commented Nov 10, 2010

Ok thank you very much for your time. I appreciate your help a lot. I will investigate on my side. Maybe it's the "formidable" library I am using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment