How can i deal with node.js/socket.io memory leak? -
what part of code cause memory leak?
i make process listener.it can listen memory's change.so know memory usage growing , never fall.sometimes can growing 800,000k , make computer crash.
the number of concurrent connections accepted 100-300.
code this:
var http = require('http').createserver(), socketio = require('socket.io').listen(http); var fs = require("fs"); var util = require('util'); http.listen(3000); var connectcount = 0; socketio.on("connection",function(socket){ connectcount++; socket.on('chatmessage',function(msg){ delete res; delete res2; //json string return client var res = { channel:msg.channel, clubname:msg.name, dn:msg.dn, . mescontent:msg.messagecontent, dn1:"", dn2:"" } var res2 = { channel:msg.channel, clubname:msg.name, dn:"", mescontent:msg.messagecontent, dn1:"", dn2:"" , curchannel:msg.curchannel } if(msg.channel == 0){ //public message socket.emit('pubmessage',res2,function(){ console.log("ok"); }); socket.broadcast.emit('pubmessage',res,function(){ console.log("ok"); }); }else if(msg.channel == 7){ //private message socket.emit('primessage',res,function(){ console.log("ok"); }); socket.broadcast.emit('primessage',res,function(){ console.log("ok"); }); } }); //cache data geter socket.on('getchatcache',function(type){ var ind = 0; socket.emit("getchatcache",type==7 ? chatcache_20.where("channel",type) : chatcache_20); }); //chat server init method socket.on('init',function(){ socket.emit('init',{chatchache:chatcache_20}); }); })
Comments
Post a Comment