Memory leak caused by ServerLevel instances persisting between worlds
ChiefArug opened this issue ยท 3 comments
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.
For my modpack fixed with this:
KostromDan/M-Tech-core@d3f3837