Mojira Archive
MC-226729

Memory leakage problem in native operations

com.mojang.blaze3d.platform.TextureUtil#readResource(inputStream) leads to memory leakage problem.

This method throws IOException. However, if it throws, this method won't return the native pointer so you can't free the memory via MemoryUtil.memFree(). For example, #readResourceAsString finally block, the ByteBuffer is null if an IOException is catched. This will take up more and more memory along with the game.

To solve this, add a catch block inside #readResource, free the memory first, and then throw the catched exception.

...
   ByteBuffer byteBuffer2 = null;
   try {
   // reading
   ...
   } catch (Throwable t) {
   MemoryUtil.memFree(byteBuffer2);
   throw t;
   }
 return byteBuffer2;

Fixed

Icyllis Milica

[Mojang] Gegy

2021-05-29, 02:27 PM

2023-02-15, 03:21 PM

2023-02-15, 03:21 PM

4

3

Plausible

Normal

Platform

Performance

memory-leak

1.16.5 - 22w03a1.16.5, 1.17 Pre-release 1, 1.17, 1.18 Release Candidate 1, 1.18.1, 22w03a

23w07a