Skip to content

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

@ChiefArug

Description

@ChiefArug

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions