Memory leak in biome cache
BlueAmulet opened this issue ยท 5 comments
This cache holds WorldGenRegion -> map(positions -> biomes), however it keeps the region objects alive in memory and over time this region -> map fills up with tons of entries and memory usage grows. I changed this to a WeakHashMap and the number of entries stayed pretty low and memory usage didn't go up after each new world.
To be clear after some digging, the processor was storing the worldgenregion which while it is a world, it's not the single world itself. It's a temporary restricted world used for worldgen which meant as you explored and generated more grassy igloos, that cache kept growing. The WeakHashmap was indeed the solution so it throws out the WorldGenRegion when it is finished with worldgen
Thank you! I'll put this in next update. How did you find the leak and narrow it down to that code?
I've actually been testing out a modpack and have been noticing over time memory fills up to the point it's doing full GC every second. In the resulting heap dumps the MINI_BIOMEPOS_CACHE object usually stood out with high amounts of memory consumption.
But yeah I also had to create several worlds back to back. I also put some debugging messages in the computeIfAbsent function that shows how many entries were in the cache every time it added a new one, since sometimes making a new world doesn't immediately trigger adding stuff to the cache.