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:
Join a singleplayer world or multiplayer server.
Wait for the world and nearby chunks to render.
Disconnect and return to the title screen.
Use a Java profiler to force a full garbage collection.
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
-> ClientLevelMinecraft.levelExtractor
-> LevelRenderState.sectionUpdateRenderStates
-> SectionUpdateRenderState.region
-> RenderSectionRegion.level
-> ClientLevelWhen disconnecting before initial chunk loading has completely finished, this path can also retain the level:
Minecraft.levelExtractor
-> LevelRenderState.playerCompiledSectionCallback
-> LevelLoadTracker.WaitingForPlayerChunk.level
-> ClientLevelTechnical 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.
Can confirm in 26.3.