Indium causes memory leak when switching worlds
embeddedt opened this issue ยท 1 comments
I'm using 1.20 with some other mods, but I think the issue is within Indium (or maybe Sodium). The previous client level can be retained by the thread local in MixinBlockModelRenderer even if the player changes dimensions. Heap dump screenshot:
A simple fix would probably be to store the world using a WeakReference
, or possibly clear the thread local when the dimension changes.
Looks like this was introduced in #167: when Indium was changed to use the Sodium AO/light caches, a SingleBlockLightDataCache
was added so that Indium could call a LightDataAccess
regardless of non-terrain/terrain rendering and always cache AO results. Note that this leak will be cleared up when pistons move blocks, or sand/gravel falls - it won't continually grow.
It also looks like the change to clear BlockRenderInfo.blockView
in FabricMC/fabric@c154966 wasn't ported in #205 - so the thread-local context is holding onto the world here as well. I've fixed that in afe94b3 and 3b66ba1.
I'm going to just make the world reference in SingleBlockLightDataCache
be cleared after every block was rendered. A potential improvement could be to store a render context per-world and clean it up when the world is unloaded, which would also allow using HashLightDataCache
from Sodium, but this simple fix works for now. (change was discussed in CaffeineMC Discord if more context is desired)