Lee Armstrong
Lee Armstrong

Reputation: 11452

Memory Leak in NodeJS

I get a memory leak in this amazingly simple code, that connects to a TCP server and sends some data down. Overnight it has used 23GB on the machine running it!

I've tried v0.12.7 and iojs version 3 and both have the same results!

var net = require("net");

var client = net.connect({
    host: '127.0.0.1',
    port: 4444
}, function() {
    console.log("Connected");
});

client.on("data", function(data) 
{
    xml = data.toString();

    console.log(xml);
});

Upvotes: 1

Views: 133

Answers (1)

Yuri Zarubin
Yuri Zarubin

Reputation: 11677

Node.js has a hard limit in terms of memory usage, which is 1.7GB, so it's impossible that your node process used that much memory. I noticed that you're console.loging all of the output. If you have your program running in a terminal, each time you console.log something it will use up memory (though I admit that 23GB is a bit excessive). So I would run this test again but without the log.

Upvotes: 2

Related Questions