Memory leak in Networking API
Ampflower opened this issue ยท 2 comments
The networking API retains copies of the server when the integrated server is shut down.
This can lead to a substantial amount of memory left allocated as chunks are never properly unloaded.
Both the ServerLoginNetworkAddon and ServerPlayNetworkAddon contains a reference to MinecraftServer, and are never removed when the server shuts down.
Below are images of the heap dump showing where instances of MinecraftServer is retained unnecessarily. The dump is a bit noisy due to presence of other mods, but this can be fully reproduced with only the API base and networking API present.
Steps to Reproduce
- Load a world. Let it load then note the memory floor when a GC hits. (i.e. 57%)
- Unload the world, then load it again. Let it load then note the memory floor when a GC hits.
Expected Results
The memory to be at the same floor (57% in this example) no matter how many times you reload the same world.
Actual Results
The memory jumps up a significant amount (roughly 3-5% for 4 GBs allocated with 32 chunk render distance). This can eventually lead to an unresolveable out of memory error condition when worlds continue to be reloaded.
Thanks for the report!
SP test with regular menu actions yields that
- the login -> play transition doesn't clean GlobalReceiverRegistry.trackedAddons up
- the client play disconnect event/processing doesn't fire, so no GlobalReceiverRegistry cleanup either
- only server play worked properly
Other actions may be incompletely covered as well, e.g. disconnects during the login stage or disconnects from the other side.
Should be fixed via #1440