BlakeBr0 / IronJetpacks

Adds fully customizable FE powered jetpacks!
https://blakesmods.com/iron-jetpacks
MIT License
13 stars 21 forks source link

Fix memory leak on client disconnect #91

Closed ViRb3 closed 3 months ago

ViRb3 commented 4 months ago

I've been profiling All the Mods 9, a heavy modpack with 400+ mods, to try and reduce the most impactful memory leaks. I discovered the maps in InputHandler transiently hold onto a reference of ClientLevel, which weighs over 300MB. Since the maps are not unloaded on client side disconnect, every rejoin of the server adds another 300MB of consumed RAM, quickly making the game very laggy.

The problem can technically be solved by only adding weak maps, or only by capturing client side disconnect and clearing, but I figured adding both is more error proof for the future. Feel free to adjust if necessary. Thanks!

BlakeBr0 commented 4 months ago

What is the need for both that additional event handler and making all the maps weak? Are there cases which one or the other doesn't cover?

ViRb3 commented 4 months ago

No, either one is fine, added both for additional safety and error proofing as mentioned in the PR. Feel free to keep only one of the two if you prefer.