Botania

Botania

133M Downloads

[1.19.2] Botania causes JEI runtime memory leak after reload

embeddedt opened this issue ยท 0 comments

commented

Mod Loader

Forge

Minecraft Version

1.19.2

Botania version

1.19.2-439-FORGE

Modloader version

43.2.13

Modpack info

All The Mods 8 v1.0.19b

The latest.log file

N/A

Issue description

The assignment of CorporeaInputHandler.hoveredStackGetter in the JEI plugin causes a memory leak if JEI is reloaded a second time, as the previous old lambda is no longer () -> ItemStack.EMPTY, and instead holds a reference to the old JEI runtime. This prevents it from being garbage collected and wastes ~600MB of memory in ATM8.

https://github.com/VazkiiMods/Botania/blob/178778902e2fd9213ccbd4c8dd167ba1543bd17e/Xplat/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java#L236C1-L242

I think a simple way to work around this, if larger code changes are not desired, would be to capture a WeakReference<JeiRuntime> inside the lambda instead of a direct reference to the runtime.

I have not tested but I assume REI/EMI may also be affected by this if they use the same logic. I am also not sure how old this code is, the leak may also be present in 1.18 and 1.16.

Steps to reproduce

  1. Launch the game and open a world.
  2. Run /reload.
  3. Use a heap dump tool to observe the old JEI runtime being retained via Botania's lambda, and nothing else.

image

Other information

No response