Why Does Mono Heap Memory Keep Growing and Trigger GC Spikes in Unity Mobile Games?
Mono Heap memory is one of the most important runtime memory systems in Unity, directly affecting both application stability and garbage collection performance. Excessive allocations, heap fragmentation, memory leaks, and long-lived managed objects can increase memory consumption and trigger GC-related frame spikes. This article explains how the Mono Heap works, clarifies common misconceptions about heap growth, and demonstrates how GOT Online can be used to locate allocation hotspots, analyze memory residency, and identify potential leaks before they impact players.
About GameOptim GameOptim helps Unity developers identify memory issues, rendering bottlenecks, and performance regressions through automated profiling and cloud based performance analysis. Explore more: 🌐 Website: www.gameoptim.com https://www.gameoptim.com/?fopt=blog 📘 Blog: www.gameoptim.com/blog/ https://www.gameoptim.com/blog/ 💼 LinkedIn: www.linkedin.com/company/gameoptim/ https://www.linkedin.com/company/gameoptim/ 🎥 YouTube: GO.PerformanceLab https://www.youtube.com/@GO.PerformanceLab 💬 Discord: GameOptim https://discord.gg/4Jh6hj9gRw ⭐ GitHub: GameOptim https://github.com/GameOptim/unity mobile performance guide 💻 Dev: GameOptim https://dev.to/gameoptim https://uwa overseas images.oss us east 1.aliyuncs.com/Blog/HeadImage/OptimizationGuide12%280%29.jpg Summary Mono Heap Memory stores managed objects created by C runtime code. Excessive heap allocation increases both memory usage and GC overhead. Unity expands the heap when free space becomes insufficient instead of triggering immediate garbage collection. Heap fragmentation can become a major source of memory inefficiency in long running sessions. Reserved Mono memory can shrink under certain conditions despite the common belief that Mono Heap only grows. Continuous per frame allocations are a common cause of frequent GC spikes. Long running leak analysis is essential for identifying hidden memory retention issues. Core Concepts Mono Heap Memory Mono Heap Memory is the runtime memory area used to store managed objects created by C code, including: String objects Lists and collections Delegates Custom class instances Boxing allocations Unlike asset memory, Mono Heap usage changes continuously during gameplay as objects are allocated and released. Unity Garbage Collection Workflow Unity manages Mono Heap memory through three major stages: 1. Object Allocation Memory is allocated whenever managed objects are created through operations such as: String concatenation Boxing Collection expansion New allocations are placed into available free heap space whenever possible. 2. Heap Expansion When available space becomes insufficient, Unity typically expands the heap instead of immediately triggering garbage collection. This behavior reduces GC frequency but increases overall memory residency. 3. Garbage Collection When GC conditions are met or GC is triggered manually: Unreferenced objects are identified Memory is reclaimed Released space becomes available for future allocations The reclaimed memory is reused internally by the heap before additional expansion occurs. Technical Framework GameOptim Step 1 — Analyze Heap Composition Mono Heap memory consists of three major components: Reserved Space Actual Object Usage Fragmented Heap Space Only actual object usage is directly controlled by developers. Reducing active object residency usually produces the largest memory savings. 43 https://uwa ducument img.oss cn beijing.aliyuncs.com/GameOptim/2.12Mono/43.png Step 2 — Identify Heap Fragmentation Frequent allocation and release patterns can gradually increase heap fragmentation. Typical symptoms include: Growing fragmented space Stable object usage but increasing Reserved Mono Reduced memory efficiency Large object and small object allocations occurring repeatedly within the same systems often contribute to fragmentation growth. Step 3 — Verify Heap Expansion and Contraction Behavior A common misconception is that Mono Heap only grows. In reality: GC released memory remains available for reuse Unity can return physical memory pages to the operating system under certain conditions Scene transitions and memory pressure events may trigger heap contraction The following test demonstrates Reserved Mono and process memory decreasing after releasing a large heap allocation and triggering garbage collection. 44 https://uwa ducument img.oss cn beijing.aliyuncs.com/GameOptim/2.12Mono/44.png 45 https://uwa ducument img.oss cn beijing.aliyuncs.com/GameOptim/2.12Mono/45.png Step 4 — Locate Allocation Hotspots Use GOT Online Mono Mode to inspect allocation call stacks. Focus on two categories: One Time Peak Allocations Large allocations commonly occur during: Initial data loading Configuration loading Scene initialization Unexpected runtime peaks require further investigation. 46 https://uwa ducument img.oss cn beijing.aliyuncs.com/GameOptim/2.12Mono/46.png Continuous Allocations Repeated allocations every frame or every few frames are often responsible for: Frequent GC activity Frame stutters Runtime instability Call stack analysis helps identify the responsible systems. 47 https://uwa ducument img.oss cn beijing.aliyuncs.com/GameOptim/2.12Mono/47.png Step 5 — Perform Leak Analysis Compare heap residency between different sampling points. This allows developers to identify: Growing object retention Long lived allocations Potential memory leaks The leak analysis view highlights which call stacks contribute to increasing heap residency over time. 48 https://uwa ducument img.oss cn beijing.aliyuncs.com/GameOptim/2.12Mono/48.png Best Practices Minimize Continuous Runtime Allocations Avoid creating new managed objects repeatedly inside: Update LateUpdate FixedUpdate Frequently executed callbacks Reducing allocation frequency directly lowers GC pressure. Control Object Residency Review systems that retain large numbers of objects for long periods. Focus on: Collections Caches Singleton managed resources Long lived managers Reduce Heap Fragmentation Avoid allocation patterns that frequently interleave: Large object allocation Large object release Small object allocation Fragmentation control improves long term memory efficiency. Investigate Allocation Peaks Large allocations during initialization may be acceptable. Unexpected spikes during gameplay should always be investigated. Conduct Long Duration Leak Testing Short tests often fail to expose memory retention issues. Long running tests provide better visibility into: Leak trends Object residency growth Heap expansion behavior Key Takeaways Mono Heap Memory directly affects both memory usage and GC performance. Excessive managed object allocation is a common source of frame time instability. Actual object residency is the primary optimization target. Heap fragmentation can significantly reduce memory efficiency during long sessions. Reserved Mono memory can shrink under specific runtime conditions. Continuous allocations often contribute more to GC spikes than occasional large allocations. Allocation stack analysis is essential for identifying problematic systems. Long duration leak testing is one of the most effective ways to uncover hidden memory issues. FAQ What is Mono Heap Memory in Unity? Mono Heap Memory stores managed objects created by C code during runtime. Why does Mono Heap memory keep increasing? Unity expands the heap when free space becomes insufficient, allowing future allocations without immediate garbage collection. Does Mono Heap only grow and never shrink? No. Unity can return unused physical memory pages to the operating system under certain conditions, causing Reserved Mono memory to decrease. What causes heap fragmentation? Frequent allocation and release of objects with different sizes can gradually create fragmented free space within the heap. Why do frequent allocations cause frame spikes? Frequent allocations increase garbage collection activity, which can introduce noticeable frame time spikes. How can allocation hotspots be identified? Allocation call stacks can be analyzed through GOT Online Mono Mode to locate systems generating excessive allocations. How can memory leaks be detected? By comparing heap residency across multiple sampling points and identifying continuously growing object retention. How long should Mono Heap leak tests run? Tests lasting at least one hour are generally more effective at exposing long term memory retention and leak issues. Continue reading the series 1. Why Do Mobile Games Crash, Lag, or Overheat? A Unified Framework for CPU, GPU, and Memory Optimization in Unity https://www.gameoptim.com/blog/post/OptimizationGuide1 2. How to Control Runtime Memory in Unity Mobile Games: PSS Standards, Memory Profiler Analysis, and Optimization Workflows https://www.gameoptim.com/blog/post/OptimizationGuide2 3. Common Resource Memory Issues in Unity Mobile Games https://www.gameoptim.com/blog/post/OptimizationGuide3 4. Why Is Texture Memory So High in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide4 5. How Do Vertex Count, Vertex Attributes, and Read/Write Settings Affect Mesh Performance in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide5 6. How Can You Reduce Animation Memory Usage and Runtime Overhead in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide6 7. How Can You Reduce Audio Memory Usage and Playback Overhead in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide7 8. How Can You Reduce Material Count and Avoid Material Related Performance Waste in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide8 9. How Can You Reduce Render Texture Memory Usage and Rendering Overhead in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide9 10. What Causes Excessive Shader Memory Usage and Variant Explosion in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide10 11. Why Do Font and Particle System Resources Consume Excessive Memory in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide11 13. Why Is Memory Usage Still High After Optimizing Unity Resources? https://www.gameoptim.com/blog/post/OptimizationGuide13 14. What Defines a CPU Bottleneck in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide14 15. Unity Rendering CPU Optimization: Why Is Rendering Time So High? https://www.gameoptim.com/blog/post/OptimizationGuide15 16. What Causes UI Performance Bottlenecks in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide16 17. Is Unity Physics Wasting CPU Time on Mobile? How to Detect and Reduce Hidden Physics Overhead https://www.gameoptim.com/blog/post/OptimizationGuide17 18. Why Is Unity Animation Taking Too Much CPU on Mobile? https://www.gameoptim.com/blog/post/OptimizationGuide18 19. How to Reduce Particle System CPU Spikes and Runtime Overhead in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide19 20. How Can I Reduce Unity Loading Time and Avoid Runtime Stutters? https://www.gameoptim.com/blog/post/OptimizationGuide20 21. How Can I Optimize Unity Logic Code, Lua, and Hotfix Runtime Performance? https://www.gameoptim.com/blog/post/OptimizationGuide21 22. How Do I Identify GPU Bottlenecks in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide22 23. How can developers accurately determine whether a Unity mobile game is GPU Bound using GPU Clocks? https://www.gameoptim.com/blog/post/OptimizationGuide23 24. How can developers identify and optimize GPU vertex stage bottlenecks in Unity mobile games? https://www.gameoptim.com/blog/post/OptimizationGuide24 25. How can developers identify and reduce GPU fragment stage bottlenecks in Unity mobile games? https://www.gameoptim.com/blog/post/OptimizationGuide25 26. How to Reduce Shader Complexity in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide26 27. How to Optimize Post processing in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide27 28. How to Reduce GPU Bandwidth in Unity Mobile Games? https://www.gameoptim.com/blog/post/OptimizationGuide28 29. Why Does My Unity Mobile Game Overheat, Drain Battery Fast, and Drop FPS After a While? https://www.gameoptim.com/blog/post/OptimizationGuide29