Alex's Mobs

Alex's Mobs

79M Downloads

Memory leak caused by ServerLevel instances persisting between worlds

ChiefArug opened this issue ยท 3 comments

commented

private static final Map<ServerLevel, BeachedCachalotWhaleSpawner> BEACHED_CACHALOT_WHALE_SPAWNER_MAP = new HashMap<>();

This field holds ServerLevel instances and is not cleared when the world closes and those levels are no longer valid. This causes the ServerLevel, and anything that it references, to stick around in memory despite no longer being used after the world is closed and a new one opened.

This can be solved by either replacing it with a WeakHashMap, which will let the garbage collector empty it when the levels are no longer in use elsewhere, or by adding a listener to the level unload event and removing levels when that event triggers.

Originally discovered by @pietro-lopes and @KostromDan but neither bothered reporting it.

commented

image
image

commented

If you fix issue with BEACHED_CACHALOT_WHALE_SPAWNER_MAP where still be a same problem but because:
image

commented

For my modpack fixed with this:
KostromDan/M-Tech-core@d3f3837