From 1f1b39a77acced33dcded436694e8d0862e9e558 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 15 Feb 2021 18:07:33 -0800 Subject: [PATCH] Free base tilesheet image after processing it This isn't a memory leak (not even Valgrind complains), because it gets properly cleaned up in GraphicsResources::destroy(). Still, it's memory that is just laying around not being used, and in the name of deallocating things as soon as you no longer need them, we should deallocate the base tilesheet images after we split all of them into tiles. This reduces the memory cost of all tilesheet images by half, since we were essentially keeping around duplicates for nothing; this doesn't really have much of an impact with conventional tilesheet sizes, since they're usually small enough, but since 2.3 allowed for tilesheet images of any size, this is a pretty big deal for really big tilesheet images. It's okay to do this, even though they also get freed in GraphicsResources::destroy(), because SDL_FreeSurface() does a NULL check on the pointer passed to it, and we set the pointer to NULL after freeing the surfaces. --- desktop_version/src/Graphics.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 1179b0f1..369d75f4 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -341,7 +341,10 @@ void Graphics::updatetitlecolours() \ extra_code \ } \ - } + } \ + \ + SDL_FreeSurface(grphx.im_##tilesheet); \ + grphx.im_##tilesheet = NULL; #define PROCESS_TILESHEET(tilesheet, tile_square, extra_code) \ PROCESS_TILESHEET_RENAME(tilesheet, tilesheet, tile_square, extra_code)