Hello everyone,
we are a studio with a released game and active playerbase.
These crashes have not been reproduced in the studio, but we get regular reports from players.
We have a system to automatically upload crash reports. I went through the 50 most recent crash reports and for every report I noted which additional info I found in the log that could be responsible. These are either from the stacktrace or logs that happened just before the crash occurred:
Again in text, for easier copy-paste:
ONE ISSUE
15 no stacktrace or other info
11 system out of memory (managed memory or nativearrays or computebuffers are <3 gbs almost always)
6 Renderer.GetMaterialArray
4 stacktrace only in unity code, not in our c# code, no other info
4 d3d11 out of memory (code 0x8007000e)
2 custom native library issue
1 custom native library issue
1 custom native library issue
1 d3d11 device loss (code 80070057)
COMBINED ISSUES
2 system out of memory AND UnityEngine.Terrain:set_materialTemplate
2 system out of memory AND d3d11 out of memory (code 0x8007000e)
1 Renderer.GetMaterialArray AND d3d11 out of memory (code 0x8007000e)
While I am interested in fixing all of these issues, it seems like at least 20 out of the 50 crashes are clearly related to memory. This also matches our player reports that from time to time, the game balloons to 30GB of memory usage. Normal memory usage is only a couple of GB.
In order to investigate the abnormal memory usage, we have started logging memory statistics.
We use System.GC.GetTotalMemory(false) to figure out how much managed memory or C# code uses. It’s always between 0.5GB and 2GB, no abnormal behaviour to be found.
This function however does not track ComputeBuffers and NativeArrays (we do not use any other native Unity collections or unsafe allocations anywhere else). So, we have created memory management facade class and do all allocations through that class. This class tracks all allocations and disposes and gives us an overview of the amount of native memory we have allocated. It seems to stay below 1GB always, not abnormal behaviour.
We do have one native C++ library in use. Without going into detail, it seems unlikely that this is the culprit (well known, well tested 3rd party lib and was used before the crash reports came in).
We tried logging total process memory consumption, but so far haven’t been successful, see here . If you got any tips on how to do that, feel free to let us know.
So now the question is what other kinds of memory does Unity allocate and how to track down what is creating the issue? From all the graphics related errors it seems that maybe Unity is holding too many textures or allocating and not releasing by mistake? We do use the virtual texturing system, maybe it’s an issue there?
So please, if you have any ideas at all about how to find out these things, share your thoughts:
- Besides managed memory, ComputeBuffers, NativeBuffers, what other memory does Unity allocate?
- How to find stats about Unity memory allocation at runtime so we can log them and observe unusual behaviour?
- The memory profiler in the profiler and window as well as the memory profiler package seem not to be available at runtime. Are parts of it accessible through scripting maybe?
- How to get more information from crash reports, especially since we can’t reproduce them in the studio. We can outfit our game with all kinds of logging and reporting capabilities if necessary.
- Do you know any way to report total process memory usage that works in Unity?
If you have any questions about the information above, let me know and I will clarify and edit.
Thanks so much for any thought, tip, or advice.


