Botania (Fabric/Quilt)

Botania (Fabric/Quilt)

7M Downloads

ManaNetworkHandler may leak client memory

Closed this issue ยท 1 comments

commented

Mod Loader

Forge

Minecraft Version

1.20.1

Botania version

1.20.1-448-FORGE

Modloader version

47.4.2

Modpack info

https://www.curseforge.com/minecraft/modpacks/ctnh

The latest.log file

N/A

Issue description

ManaNetworkHandler may leak memory due to the value reference the level key.

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/WeakHashMap.html

Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. Thus care should be taken to ensure that value objects do not strongly refer to their own keys, either directly or indirectly, since that will prevent the keys from being discarded.

The following images show the GC root. Used VisualVm to dump memory.

Image Image

Steps to reproduce

  1. Join a online server with botania mod
  2. Switch to a different world within the server. Ensure the target world contains Botania mod flowers (e.g., functional or generating flowers).
  3. Switch to a different world.
  4. Repeat step 2 3 above.
  5. Observe memory behavior
  • After switching, monitor memory usage via the F3 debug screen or external profiling tools.
  • Memory usage increases in proportion to the new world's actual memory footprint.
  • Even after triggering garbage collection, the memory is not released.

Other information

Quit the server and rejoin will fix the memory leak. But in the modpack case, rejoin server will leak memory by other mods.

commented

A quick fix would probably be to just derive the value sets from WeakHashMap.
That entire class might be worth further investigation for the 1.21 port, as it probably won't scale too well if players on a server really go ham with the spreaders and pools.