public Messenger(Socket socket, string username)
{
sock = socket;
controller = new SocketHandler.Controller(socket);
controller.onReceiveData += ParseMessage;
controller.onCloseConnection += OnCloseConnection;
}
...
if (game == Messenger.GAME_TOKEN)
{
new Messenger(socket, username);
}
I don't want to have to manage some reference to the new instance of the Messenger class that I create. Will the reference to the private method that I add to the onCloseConnection Action in the controller suffice to keep the Messenger instance from being garbage collected?
I could always be on the safe side and manage it but the simpler the better.