Memory Leak of ServerPlayer (1.20.1)
pietro-lopes opened this issue ยท 3 comments
While players
is a WeakMap, the value has an object that stores player so it prevents the GC to collect ServerPlayer, leaking when the player leaves the world and go to login screen.
@Mari023 for a quick backport fix, can you not change the Player field to a WeakReference? This should prevent the cyclical reference with your map that keeps Player loaded forever, as long as this Player object is maintained by another strong reference in the server.
@ViRb3 theoretically yes, but that would be quite annoying as the player can potentially be null at random places (tho arguably this is unlikely, since it only gets called from an existing player), and the current code doesn't deal with this possibility.
Also I don't really want to deal with the older versions unless absolutely necessary.