I wrote the code below using nodejs AND socket.io for a simple socket application (just plug and unplug), there will not be much user memory to use 50, but for up to 300 users and after one hour the memory usage just grows (about 300 MB for server.js proccess and grow in time), it looks like nodejs are not freeing memory.
var server = require('http').createServer(); var io = require('socket.io')(server); var port = 9090; var sockets = {}; server.listen(port, function () { console.log('Server listening at port ', port); //timer and logs are not problem , i tested it before. setInterval(function(){ console.log(Object.keys(sockets).length+' Online Devices At '+Date()); }, 1000 * 60 * 1); }); io.on('connection',function(socket){ sockets[socket.id]={id:socket.id}; console.log('connected '+socket.id + ' count ' + Object.keys(sockets).length); socket.on('disconnect', function (data) { delete sockets[socket.id]; console.log('disconnected '+socket.id+ ' count ' +Object.keys(sockets).length); }); });
Am I doing something wrong ?!
Edit
14 hours after starting the file with forever 
300 open sockets and about 500 MB of memory usage associated with my nodejs process.
Edit
After 16 hours, 300 connected sockets
After the termination of the process. 
Edit
loot in my new code, please.
var server = require('http').createServer(); var io = require('socket.io')(server); var port = 90; var counter = 0; var clients = {} server.listen(port, function () { console.log('Server listening at port ', port); }); io.on("connection",function(socket){ clients[socket.id] = socket; counter++; socket.on('disconnect', function (data) { counter--; delete clients[socket.id]; }); });
I am trying to use this with 1000 connected users (another server simulates user requests and open sockets)
memory usage before launch: 100 MB, after 5 minutes and 1000 stable open connections: 400 MB