From 9dd91d1c2cfe7b836969673ef5d13957eeee7df7 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Tue, 6 Apr 2021 03:29:13 +0100 Subject: [PATCH] Save 1.3 MiB RAM in-game by freeing menu resources Running with a memory profiler revealed that we were keeping main menu UI resources around while the game was running. --- Source/diablo.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 275c396f2..7fd4b2f31 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -377,6 +377,10 @@ BOOL StartGame(BOOL bNewGame, BOOL bSinglePlayer) break; } + // Save 1.3 MiB of RAM by freeing all main menu resources + // before starting the game. + UiDestroy(); + gbSelectProvider = FALSE; if (bNewGame || !gbValidSaveFile) { @@ -392,6 +396,11 @@ BOOL StartGame(BOOL bNewGame, BOOL bSinglePlayer) run_game_loop(uMsg); NetClose(); pfile_create_player_description(NULL, 0); + + // If the player left the game into the main menu, + // initialize main menu resources. + if (gbRunGameResult) + UiInitialize(); } while (gbRunGameResult); SNetDestroy();