此代码的哪一部分会导致内存泄漏?
我创建了一个进程监听器。它可以监听内存的变化。所以我知道内存使用量正在增长而且它永远不会下降。有时它会增长到800,000k并导致计算机崩溃。
接受的并发连接数约为100-300。
这样的代码:
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 for return to 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});
});
})