mojira.dev
MC-101233

Burned out redstone torch map causes memory leak

Note

The following is based on a decompiled version of Minecraft 1.9 using MCP 9.24 beta.

The bug

The field net.minecraft.block.BlockRedstoneTorch.toggles is a map with Worlds (like Overworld, End and Nether) as key and a list of redstone torch states as value. The problem is that a world is never removed from this list, which means that all save files you load containing redstone torches that burned out have still a reference in this list and cannot be collected by the garbage collection.

In general it might be better to use a TileEntity to store this value. But I am not too familiar with what effect this would have on performance.

@unknown: Alternatively, using a WeakHashMap would also solve this, as it would allow the World to be collected without having to do any extra work.

Comments 4

After stumbling upon this issue in the wild, I did some various tests and can confirm that this is an issue. The block class for the redstone torch has a HashMap which stores a reference to the world object as a key. These keys are never removed, so the size of map will continue to increase. Because the world is being referenced by the map it can not be fully garbage collected. This can be fixed extremely easily, simply change from a HashMap to a WeakHashMap.

Is this still an issue in the latest snapshot 16w44a? If so please update the affected versions.

This is an automated comment on any open or reopened issue with out-of-date affected versions.

@unknown: can you check and see if this is still a thing in 1.11.2?

It should still be the case. The map is still there and there are no methods which remove entries from the map.

marcono1234

Fry

Confirmed

(Unassigned)

memory-leak, redstone_torch, world

Minecraft 1.9.2, Minecraft 1.11.2, Minecraft 1.12.2, Minecraft 18w15a, Minecraft 1.13, Minecraft 18w30a, Minecraft 18w30b

Minecraft 1.14 Pre-Release 4

Retrieved