Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-226729

Memory leakage problem in native operations

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 23w07a
    • 1.16.5, 1.17 Pre-release 1, 1.17, 1.18 Release Candidate 1, 1.18.1, 22w03a
    • Plausible
    • Performance
    • Normal
    • Platform

      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;
      

            gegy1000 [Mojang] Gegy
            BloCamLimb Icyllis Milica
            Votes:
            4 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: