Hello, I’ve been monitoring an issue in my VR project (using HDRP) where what appears to be excessive “untracked - private” RAM usage occurs. I’ve reached the limits of my own skills trying to diagnose the cause of this. Specifically, within my main scene—on frame 0, both in builds and when entering Play mode in the Editor—there is a giant allocation of around 3 GB of unmanaged private RAM. This represents about 60% of my game’s total RAM usage, and I have no idea how to control or diagnose it.
My primary concern: In all test scenes and scenarios I’ve tried, “unmanaged - private” RAM usage never falls below about 40% of the total RAM usage, as reported by Task Manager. I believe the total listed under “All of Memory” might include graphics memory on the GPU, but I’m not certain.
I found very little information on what could cause “untracked - private” RAM. This forum post was the most helpful resource, which is why I’m tagging @MartinTilo. Your first response there helped me start narrowing down potential causes in my project.
To summarize, you listed these possible causes:
- Native Plugin allocations
- The size of Executable and DLLs
- Stack Memory
- VMs using IL2CPP (not applicable, since I’m using Mono)
- Memory allocated using
Marshal.AllocHGlobal
(which I’ve never used, so if this were the cause, it’d have to be one of the external DLLs)
This left me with the first three items as possible culprits. I spent a day testing various combinations to see if any might be responsible.
I use three C/C++ precompiled plugins that could add to “untracked private” memory:
All tests were run on the latest version of Unity (6.0.31f1) with the latest stable package versions. All numbers reported are from Development Windows builds—Release builds show the same issues.
Next, I included the three native plugins. As expected, total RAM usage doubled to just under 1 GB, in line with what I anticipated from “untracked private” source #2 (the plugins’ uncompressed size is about 500 MB across their DLLs). This suggests that none of them individually caused the specific spike in my main project. What’s odd is that the ratio of “untracked private” stayed consistent at about 40%.
Here are the two above tests under the “compare snapshots view”:
At this point, I was clueless about potential rabbit holes I could even investigate. In my main scene, the “untracked private” RAM is 2.75 GB, while the test scenario with the same set of DLLs uses only 420MB. Both load and run the same 3rd party DLLS, yet the memory usage differs drastically.
In desperation, I tried importing the full demo scene into my main project’s environment. I compiled the XRIK test scene as the first scene in the build list to see if that changed anything. It did—but not favorably. “Unmanaged private” RAM increased to about 700 MB / 1.2 GB (~58%) when loading directly into the XRIK scene (with my project’s content present but not loaded):
For comparison, here is an identical build where my scene was the first in the build list (so it loads first). I mostly used the same post-processing stack in both scenes to see if it mattered—it did not.
In the above comparison, “A” represents the initial build (first photo in this post) loading directly into my main scene (showing the severe issue), while “B” is the snapshot from the previous photo.
I’m truly at a loss for what could be causing this issue. I’m worried it might worsen and become even harder to fix later on. The only approach I can think of now is to try “hail-mary” builds, removing random components from my game to see if anything helps. But since this massive RAM allocation occurs on frame 0, before most of my gameplay systems have time to run (I have most of them initialize a few frames later), making them unlikely culprits. Moreover, my main scene uses over 2 GB more “untracked private” RAM than the demo scene within the exact same project.
If anyone has any ideas, I’d love to hear them. I don’t know how to create a repro case without submitting my entire 5-year-old project as a bug report.
I also don’t know how to test point #3 (stack memory issues). I highly doubt it’s stack-related since the total C# RAM usage doesn’t surpass 200 MB.
In the short-to-medium term, I can live with this problem since most PCs that run VR can handle an extra 3+ GB of unexplained RAM usage, and the amount doesn’t grow over time. However, I’m worried about console releases like PS5, or porting to Quest2 with URP, where total available RAM for apps to use is under 3 GB. In that scenario, this bug alone would break the build.
If anyone has insights, I’d greatly appreciate them.
Best Regards,
Colin