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

Warn against using particular worldbound classes in fields or as generic arguments in Map/List ect in fields. #2396

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

Comments

@ChiefArug
Copy link

Minecraft Development for IntelliJ plugin version

N/A

Description of the feature request

Memory leaks caused by Level, Player and sometimes even Entity instances persisting between world loads are quite common, caused by mod devs using a field like public static Map<ServerLevel, SomethingElse> stuff = new HashMap<>();. A warning against these would in the IDE let the mod author know that it can cause issues and help prevent some of them. In particular for a HashMap using one of those classes as a key it can be solved by replacing it with a WeakHashMap, which will let the keys be GCed away, otherwise the solution is typically listening to unload events and clearing the contents of the field there.

An example of one of these memory leaks:
https://github.com/AlexModGuy/AlexsMobs/blob/0d7bea8f643bff978ff2b9e4690f3c2a1a514266/src/main/java/com/github/alexthe666/alexsmobs/event/ServerEvents.java#L109

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

No branches or pull requests

1 participant