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

CommandBase.commandListener retains old server reference, preventing garbage collection

XMLWordPrintable

    • Confirmed

      During server startup, ServerCommandManager() calls CommandBase.setCommandListener() with itself as the argument.

      This means that the CommandBase class holds a staic reference to the command manager, which holds a reference to the server.

      As the server holds references to many game objects, this link keeps a fairly large amount of memory from being garbage collected if the application continues, which is the case for the single-player client.

      This can be seen by starting the single-player client, loading a world, and then quitting to the title screen, then taking a heap dump of the application.

      While this is not a permanent leak, as the field will eventually be overwritten, it causes memory to stay in use a lot longer than it would otherwise, and increases memory demands to load subsequent worlds.

      A solution here would be to add a call to CommandBase.setCommandListener(null) in MinecraftServer.stopServer(), either directly or through ServerCommandManager.

            Unassigned Unassigned
            quadraxis Ben Staddon
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: