Multiverse / Multiverse-Inventories

BSD 3-Clause "New" or "Revised" License
93 stars 81 forks source link

Wrong usage of WeakHashMap in weak container and weak container store. #506

Open MrMks opened 2 years ago

MrMks commented 2 years ago

WeakHashMap is a weak key but strong value map, but in those files, String is used as the key. String is something will always exist hold by jvm or something exist for a short period. So use string as key can't match your aim.

Because player name may be held by other plugins, using a String as the key here will make WeakHashMap unable to remove those PlayerProfiles in necessary. And, PlayerProfile contains a Player reference, it finally causing a memory leak problem.

To patch this problem, I recommend to remove those profiles manually by invoking remove method on Map of profiles when a player logs out and on Map of containers when a world unload.

(Required information in template has no value here, but if your guys really need them to fix this problem, I will post them in reply.)