mojira.dev
MC-261339

Memory Leak in Minecraft (Offheap, Rendering)

This issue seem to affect all published version

The offheap memory grows and grows. 1.19.4:

JavaArgs: -Xmx2G (-Xms2G -XX:NativeMemoryTracking=summary)=only added for observing -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M
Settings: viewdistance: 12, fps: unlimited

results after joining world, letting finish loading, playing since 15min:

gpumem: 0,2GB (dedicated)
heapusage: 31%
NMT commit: 345MB + java: 2097MB = 
process commit: 3173MB

results after playing another 30min:

gpumem: 1,4GB (dedicated)
heapusage: 32%
NMT commit: 375MB + heap: 2097MB = 2472MB
process commit: 5105MB

A lof of this memory is written to pagefile, with plenty of memory avaible which means that the memory seems measured as inactive. I highly doubt memory for rendering should be every stored in the pagefile... what would be the benefit?.... All the pagefile is getting eaten up and Sysmain lags the game to hell. The game keeps freezing right before the process grows. The values are very unstable unlike i remmeber it to be. 

Why is the native code using so much memory? Why does it grow constantly?
In Legacy Versions of Minecraft the Leak can reach 9gb and more with same settings/jvm args.
 
Seems happening since a Windows Update between February and June in 2022 to my knowledge. I have also reported it there already, because more applications are affected in different ways. All Minecraft Versions are affected, the more pressure the worse. It seems like the bug is not caused by MInecaft itself tho. 
What I expected to happen was...:
It should be around 2700MB and stable, not growing

What actually happened was...:
growing to 5100MB and more, unstable, eating pagefile

Steps to Reproduce:
1. Start Minecraft and fly around in the world, Doesnt matter if chunks have been loaded or generated before. This is why i suspect rendering to be the issue.
2. Monitor the committed memory while doing so. Please do not use Taskmanager since it does not show paged. Use resmon.

Linked issues

Attachments

Comments 6

⚠️ Please do not mark Unreleased Versions as affected. You don't have access to them yet.

-- I am a bot. This action was performed automatically! If you think it was incorrect, please notify us on Discord or Reddit

Does MC-173001 describe your issue?

No, the leak is outside of the java heap and not server side. Its not happening on the server side at all. Please dont mark as resolved.

Another Test:
I have 8GB of ram, 2,5GB used by operating system and 3GB allocated to minecraft, f3 screen shows 1,4gb-1,9gb used memory, allocating more memory does make it worse

[Info: 2023-06-07 12:23:58.2879288: MinecraftJavaLoggingContext.cpp(52)] Game/game () Info # There is insufficient memory for the Java Runtime Environment to continue.
[Info: 2023-06-07 12:23:58.2879725: MinecraftJavaLoggingContext.cpp(52)] Game/game () Info # Native memory allocation (malloc) failed to allocate 4088 bytes for AllocateHeap
[Info: 2023-06-07 12:23:58.3186025: MinecraftJavaLoggingContext.cpp(52)] Game/game () Info # An error report file with more information is saved as:
C:\Users\Public\minecraftprofiles\profile-1\hs_err_pid1432.log
[Info: 2023-06-07 12:23:58.5109157: MinecraftJavaLoggingContext.cpp(52)] Game/game () Info AL lib: (EE) alc_cleanup: 1 device not closed
[Info: 2023-06-07 12:23:58.9802270: MinecraftJavaLoggingContext.cpp(52)] Game/game () Info java.lang.OutOfMemoryError
[Info: 2023-06-07 12:23:58.9802995: MinecraftJavaLoggingContext.cpp(52)] Game/game () Info java.lang.OutOfMemoryError
[Info: 2023-06-07 12:23:59.6126695: MinecraftJavaLoggingContext.cpp(52)] Launcher/monitor (Process Monitor) Fatal Process crashed

Update: Still happening in 1.20.

New Thing: For all Minecraft versions, fps have been decreased and cpu & gpu usage increased, lwjgl calls seem to consume a lot more than before. Can confirm no changes to lwjgl library files or gameinstallations. Only possibilty seem to be windows or minecraft launcher.

Still happening in 1.20.2

Sagub2

(Unassigned)

Plausible

Platform

Normal

Performance

Memory-usage, chunk-loading, chunk-updates, lag, memory, memory-allocation, memory-leak, memory-spikes, rendering, world

1.19.4, 23w12a, 1.20, 1.20.1, 23w33a, 1.20.2, 23w45a

Retrieved