From 6f09d1a2f43eb75ef6e6222bf010e2900c9b9df2 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sun, 1 Nov 2015 17:50:38 +0000 Subject: [PATCH] Remove event handler when disposed in MainMenuLogic. Removes a static event handler to Game.OnRemoteDirectConnect which allow the GC to reclaim the MainMenuLogic class after it has been disposed. --- .../Widgets/Logic/MainMenuLogic.cs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs index 698f679156..c64aa3a0e7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs @@ -217,17 +217,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic } } - Game.OnRemoteDirectConnect += (host, port) => + Game.OnRemoteDirectConnect += OnRemoteDirectConnect; + } + + void OnRemoteDirectConnect(string host, int port) + { + menuType = MenuType.None; + Ui.OpenWindow("MULTIPLAYER_PANEL", new WidgetArgs { - menuType = MenuType.None; - Ui.OpenWindow("MULTIPLAYER_PANEL", new WidgetArgs - { - { "onStart", RemoveShellmapUI }, - { "onExit", () => menuType = MenuType.Main }, - { "directConnectHost", host }, - { "directConnectPort", port }, - }); - }; + { "onStart", RemoveShellmapUI }, + { "onExit", () => menuType = MenuType.Main }, + { "directConnectHost", host }, + { "directConnectPort", port }, + }); } void LoadMapIntoEditor(Map map) @@ -362,5 +364,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic OpenSkirmishLobbyPanel, () => { Game.CloseServer(); menuType = MenuType.Main; }); } + + protected override void Dispose(bool disposing) + { + if (disposing) + Game.OnRemoteDirectConnect -= OnRemoteDirectConnect; + base.Dispose(disposing); + } } }