socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Mermory usage still exists when clients disconnected

Open RavenZZ opened this issue 12 years ago • 1 comments

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..

RavenZZ avatar Oct 21 '14 05:10 RavenZZ

Oh,.. This problem can be solved by execute gc() Manually Closed

RavenZZ avatar Oct 21 '14 11:10 RavenZZ