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
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.
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.