Last active
August 29, 2015 14:07
-
-
Save danypype/a2c46da944a0eeb96b7f to your computer and use it in GitHub Desktop.
Node.js' net socket memory leak?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"heapdump": "^0.2.10" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require("net") | |
, heapdump = require("heapdump"); | |
function onConnection (client) { | |
client.on("data", function (data) { | |
client.end(); | |
}); | |
}; | |
function onListen () { | |
var socket = net.connect({host: "127.0.0.1", port: 3000}); | |
socket.bigBuffer = new Buffer(50000000); //50MB Buffer | |
heapdump.writeSnapshot(__dirname + "/initial.heapsnapshot", function writeInitialSnapshot () { | |
console.log("Wrote initial heap snapshot"); | |
socket.write("data"); | |
}); | |
socket.on("close", function () { | |
writeEndSnapshot(); | |
}); | |
}; | |
function writeEndSnapshot () { | |
setTimeout(function () { | |
console.log("Running GC"); | |
gc(); | |
heapdump.writeSnapshot(__dirname + "/final.heapsnapshot", function writeFinalSnapshot () { | |
console.log("Wrote final heap snapshot"); | |
}); | |
}, 1000); | |
}; | |
net.createServer(onConnection).listen(3000, onListen); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment