Skip to content

Replace Z_Unlock with Z_Free

mazmazz requested to merge mazmazz_/SRB2:texture-memory into master

Z_Unlock appears to have been a stub this whole time, so memory wouldn't get released upon calling it.

Are there any ill effects to using Z_Free instead?

The issue was that R_LoadTextures was locking a significant amount of RAM on game startup. I believed that it was loading every texture (4,300+) for later use.

But when I free the lump caches in Rloadflats/Rloadtextures, the levels seem to work just fine. In those two functions, the lump caches were only used to check data, and not retained in a persistent variable.

Before Fix (master)

Before R_LoadTextures()

Total heap used   :    3768 KB
Static            :    3322 KB
Static (sound)    :       0 KB
Static (music)    :       0 KB
Locked cache      :      10 KB
Level             :       0 KB
Special thinker   :       0 KB
All purgable      :       0 KB

After R_LoadTextures()

Memory Info
Total heap used   :   91990 KB
Static            :    3759 KB
Static (sound)    :       0 KB
Static (music)    :       0 KB
Locked cache      :   87794 KB
Level             :       0 KB
Special thinker   :       0 KB
All purgable      :       0 KB

On GFZ1 load

Total heap used   :  126120 KB
Static            :   27203 KB
Static (sound)    :       0 KB
Static (music)    :     961 KB
Locked cache      :   90641 KB
Level             :    5484 KB
Special thinker   :      11 KB
All purgable      :       0 KB

After Fix

Before R_LoadTextures()

Memory Info
Total heap used   :    4167 KB
Static            :    3322 KB
Static (sound)    :       0 KB
Static (music)    :       0 KB
Locked cache      :      10 KB
Level             :       0 KB
Special thinker   :       0 KB
All purgable      :       0 KB

After R_LoadTextures()

Memory Info
Total heap used   :    5404 KB
Static            :    3759 KB
Static (sound)    :       0 KB
Static (music)    :       0 KB
Locked cache      :      10 KB
Level             :       0 KB
Special thinker   :       0 KB
All purgable      :       0 KB

On GFZ1 load

Memory Info
Total heap used   :   46125 KB
Static            :   27203 KB
Static (sound)    :       0 KB
Static (music)    :     961 KB
Locked cache      :    7715 KB
Level             :    5484 KB
Special thinker   :      11 KB
All purgable      :       0 KB
Edited by mazmazz

Merge request reports