Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak caused by ServerLevel instances persisting between worlds #2165

Open
ChiefArug opened this issue Nov 21, 2024 · 3 comments
Open

Comments

@ChiefArug
Copy link

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.

@KostromDan
Copy link

image
image

@KostromDan
Copy link

KostromDan commented Nov 21, 2024

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

@KostromDan
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants