Reputation: 653
I have memory leak in my js multiplayer game. I bind a lot of callbacks when client is connected to the server. My question is do i have to unbind callbacks before deleting socket from the table of players ?
Here is my sample callback:
Player.prototype.viewPortListenerInit = function(){
var self = this;
this.socket.on('clientViewPortResize', function(data){
self.clientViewPort = data;
});
};
Here is adding player to the list/hashset of players :
this.list[socket.id] = new Player(socket);
And here is deleting:
socket.on('disconnect', function(){
delete this.list[socket.id]
});
Upvotes: 3
Views: 95
Reputation: 5317
When there are no references to instance EventEmitter
(like socket), it's garbage collected with its callbacks.
Upvotes: 2