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;
2021-05-29, 02:27 PM
2023-02-15, 03:21 PM
2023-02-15, 03:21 PM
4
3