productive-bees
productive-bees copied to clipboard
Fix memory leak on client disconnect
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 that the cache object in BeeIngredient transiently holds onto a reference of ClientLevel, which weighs over 300MB. Since the cache is never unloaded, every rejoin of the server adds another 300MB of consumed RAM, quickly making the game very laggy.
My proposed fix is not particularly beautiful, but I can confirm it works. Since WeakHashMap only holds a weak reference to the key, and that one won't expire, we need to manually wrap the value in WeakReference.
If you have any better approaches, please feel free to implement them. Thanks!