socket.io
socket.io copied to clipboard
Mermory usage still exists when clients disconnected
server code :
var server = require('http').createServer();
var io = require('socket.io')(server);
io.on('connection', function (socket) {
socket.on('event', function (data) { });
socket.on('disconnect', function () { });
});
server.listen(9997);
setInterval(function () {
console.log('client count :' + Object.keys(io.sockets.server.eio.clients).length );
console.dir(process.memoryUsage());
}, 1000);
client code :
var url = 'http://localhost:9997';
var SocketClient = function (name) {
var _this = this;
this.Socket = null;
this.connect = function () {
_this.Socket = require('socket.io-client')(url, { forceNew: 1 });
_this.Socket.on('connect', function () {
_this.Socket.on('disconnect', function () {
console.log('disconnected');
});
setTimeout(function () {
_this.Socket.disconnect();
}, 10000);
});
}
};
var socketList = [];
for (var i = 0; i < 1000; i++) {
var s = new SocketClient('user' + i);
s.connect();
}
run the server.js ,then run client.js when clients disconnected, heapTotal still in high level..
Oh,.. This problem can be solved by execute gc() Manually Closed