mojira.dev
MC-310862

The client keeps the `ClientLevel` from the last world it was in in memory after exiting

Description:
After disconnecting from a world or server, the previous ClientLevel remains strongly referenced by Minecraft’s rendering state. It cannot be garbage collected while the player remains on the title screen.

The issue is minor: the retained level is normally released after another world is loaded, so this appears to retain the most recently unloaded world rather than accumulating every previously loaded world.

Steps to reproduce:

  1. Join a singleplayer world or multiplayer server.

  2. Wait for the world and nearby chunks to render.

  3. Disconnect and return to the title screen.

  4. Use a Java profiler to force a full garbage collection.

  5. Inspect the heap for instances of net.minecraft.client.multiplayer.ClientLevel.

Expected result:
The disconnected ClientLevel has no strong references and can be garbage collected.

Actual result:
The old ClientLevel remains strongly referenced through Minecraft’s renderer. Observed reference paths include:

Minecraft.levelRenderer
 -> visibleSections
 -> RenderSection.lastCompileTask
 -> RenderSectionRegion.level
 -> ClientLevel
Minecraft.levelExtractor
 -> LevelRenderState.sectionUpdateRenderStates
 -> SectionUpdateRenderState.region
 -> RenderSectionRegion.level
 -> ClientLevel

When disconnecting before initial chunk loading has completely finished, this path can also retain the level:

Minecraft.levelExtractor
 -> LevelRenderState.playerCompiledSectionCallback
 -> LevelLoadTracker.WaitingForPlayerChunk.level
 -> ClientLevel

Technical details:

LevelExtractor.setLevel(null) clears its direct level field, but only sets shouldResetLevelRenderData. The renderer cleanup is deferred until another level extraction occurs. No level extraction occurs while on the title screen.

Linked issues

Comments 1

mezz

(Unassigned)

Community Consensus

Platform G

Normal

Performance

26.2, 26.3

Retrieved