dlee13/hold-that-chunk

[Bug]: GPU Memory Leak

Closed this issue · 4 comments

When using hold-that-chunk and traveling long distances in game, GPU memory usage increases unbounded until it maxes out and the game starts aggressively stuttering. This happens with hold-that-chunk being the only installed mod. This happens faster when using Iris and shaders as they consume more GPU memory per chunk.

To reproduce:
Open windows taskmanager and monitor GPU performance - specifically Dedicated GPU memory usage.
Equip Elytra and fly any direction and observe GPU memory usage increase and never decrease.
I've tested on a machine with 16GB of GPU memory, and when using Iris + a shader pack, I run out of GPU memory after traveling roughly 2000 blocks. It takes 2-3 times further without shaders.

Minecraft 1.19.2
holdthatchunk 1.1.1

The chunk cache using a bunch of memory is not inherently a leak. The whole premise of this mod is to hold chunks in memory until the configured amount of delay time has passed, so it is a given that memory use stays higher compared to without the mod. If you're running into memory issues, you need to adjust the memory limit in your java args (use -Xmx3G or -Xmx4G) and/or add a memory optimization mod such as FerriteCore. You may also set the chunkUnloadDelayInTicks option lower in Hold That Chunk's config so that chunks unload sooner.

I am, however, considering doing a rewrite of the mod so that it unloads chunks based on configurable distance instead of time.

Thanks for the follow-up - you're right, it's not technically a memory leak. The reason I called it that is because this is VRAM on the GPU, which is unaffected by the -Xmx argument and is never garbage collected. I use -Xmx4G, but my GPU memory usage hits 16GB. I'm not sure if within a mod you have the capability to differentiate between RAM and VRAM, but VRAM should only be used for data that's being currently shown on screen - this is likely a limitation of the renderer.

Unloading based on distance I do think would solve the issue in this particular case - the problem I'm seeing is when I'm travelling thousands of blocks with elytra in a very short amount of time, which forces the textures and geometry for all those chunks into VRAM and doesn't remove them before my graphics card runs out of memory.

The rewrite has been pushed to the 2.0.0 branch. It would be helpful to me if you could grab the build artifact from actions and see whether it resolves this issue for you.

holdthatchunk 2.0.0 was released.