DEV Community

Cover image for Why Do Unity Games Crash After Running for a While? How to Find and Fix Memory Bottlenecks
GameOptim
GameOptim

Posted on • Edited on

Why Do Unity Games Crash After Running for a While? How to Find and Fix Memory Bottlenecks

🌐 Website: www.gameoptim.com

Summary

  • Runtime memory issues in Unity are primarily reflected in PSS Total, which represents actual physical memory usage of a process.
  • RSS Total tends to overestimate memory usage due to full inclusion of shared libraries, making it less reliable for diagnosis.
  • Android OOM crashes occur when system memory pressure forces termination of low-priority processes such as games.
  • Unity Memory Profiler alone is insufficient; system-level tools like adb dumpsys meminfo are required for full memory analysis.
  • Memory issues should be decomposed into Tracked Memory, Untracked Memory, and system-level Native Heap usage.
  • Safe PSS memory usage should remain below 50–60% of total device RAM to avoid crash risk.

1. Runtime Memory Usage Analysis

PSS Total (Primary Runtime Metric)

PSS Total represents the actual physical memory usage of a process, where shared memory is proportionally distributed across processes.

It is the most accurate metric for evaluating Unity runtime memory footprint.

RSS Total(Secondary Reference Metric)

RSS Total includes full shared library memory in each process.

This leads to inflated memory values and reduces its diagnostic reliability compared to PSS.

Runtime Memory Risk Mechanism

When system memory usage reaches a high threshold:

  • Android OS triggers memory pressure recovery
  • Low-priority processes (including games) are terminated first
  • This leads to Out-of-Memory (OOM) crashes in crash logs

1. Unity Memory Profiler Analysis

Unity Memory Profiler provides two major versions with structural differences:

Memory Profiler 0.7.1
1

Key characteristics:

Clear separation of In use vs Reserved memory
Summary view divides memory into three main categories
Reserved memory reflects engine allocation overhead

2

Limitation:

  • Inconsistent category hierarchy
  • Requires manual filtering for meaningful breakdown (e.g., Manager, SerializedFile)

Memory Profiler 1.1.0
3

Improvements:
Simplified summary structure
Expanded classification into five asset types
Improved usability for diagnosis

Limitation:
Reserved memory is merged into Native
IL2CPP VM memory appears as Unknown

4

5

Key observation:

  • Large Unknown memory often originates from:
    • AssetBundle compression (e.g., LZMA)
    • VM / system-level allocations
  • Not all Unknown memory indicates leakage

2. System-Level Memory Analysis (ADB)

Unity profiling must be validated at system level:
adb shell dumpsys meminfo package_name/pid

6

Key memory components:

  • Native Heap
  • Gfx dev / EGL mtrack / GL mtrack
  • Unknown

Memory Attribution Rules

  • Unity rendering memory → Gfx / EGL / GL mtrack
  • External libraries/plugins → Native Heap / Unknown
  • System-level allocations → Unknown

Diagnostic Conditions

Memory risk is likely when:

  • Gfx + EGL + GL + Unknown >> Unity Tracked Memory
  • Native Heap shows continuous growth trend

Engineering Strategy

  • Use A/B builds to isolate plugin memory impact
  • Use plugin-native profilers (e.g., Wwise)
  • Use GOT Online Lua Mode for Lua-heavy projects
  • Use Perfetto for deep Native Heap tracing

GameOptim Insight

Native Heap growth is one of the most common hidden memory issues in production Unity projects and cannot be fully diagnosed using Unity tools alone.

Best Practices

  • Always prioritize PSS Total over RSS Total for crash analysis
  • Combine Unity Profiler + adb + Perfetto for full-stack memory tracing
  • Monitor Unknown memory as a diagnostic signal, not a final conclusion
  • Separate asset memory and runtime heap memory in analysis
  • Validate plugin memory behavior using A/B builds
  • Avoid relying on single-frame snapshots for memory diagnosis

Key Takeaways (Runtime Memory)

  • PSS Total is the most reliable runtime memory metric in Unity mobile games
  • RSS Total overestimates memory due to full shared library accounting
  • Android OOM is triggered by system memory pressure, not just app usage
  • Unity Memory Profiler must be combined with system-level tools for accuracy
  • Unknown memory is not always a leak signal
  • Native Heap growth is a key indicator of external memory issues

2. Memory Parameter Standards

Safe Memory Threshold Principle

Game crash risk increases significantly when PSS exceeds:
→ 50%–60% of total device RAM

This threshold reflects Android system memory pressure behavior.

Mono Heap Sensitivity

Mono heap affects:

  • GC pause duration
  • Runtime allocation stability
  • Memory fragmentation risk

It requires stricter monitoring than other memory types.

Device-Level Memory Safety Limits

  • 2GB devices → PSS ≤ 1GB
  • 3GB devices → PSS ≤ 1.5GB
  • 4GB devices → PSS ≤ 2GB
Memory Type Recommended Value
2G 3G 4G
Total Memory PSS Total 1 GB 1.5 GB 2 GB
Reserved Total 700 MB 1.2 GB 1.5 GB
Resources Memory Texture 140 MB 210 MB 280 MB
Mesh 60 MB 100 MB 140 MB
Shader 40 MB 50 MB 60 MB
Animation Clip 40 MB 60 MB 80 MB
Mono Heap Memory 80 MB 100 MB 120 MB
Lua Memory 100 MB 100 MB 100 MB

Asset & Pipeline Standards

  • Define memory budgets early in production
  • Translate budgets into art production constraints
  • Enforce compliance via automated validation tools
  • Segment assets into quality tiers when needed
  • Maintain alignment between engineering and art teams

Best Practices

  • Set memory ceilings based on device tiers early in development
  • Prioritize PSS reduction over Reserved optimization
  • Treat Mono heap as a high-risk GC factor
  • Automate asset compliance checking in pipelines
  • Validate memory impact using real device testing
  • Adjust standards based on project type (2D vs 3D)

Key Takeaways (Memory Standards)

  • Safe PSS usage should remain within 50–60% of device RAM
  • Mono heap has a direct impact on GC performance and stability
  • Texture memory is the dominant contributor in most Unity projects
  • Memory budgets must be enforced through pipeline automation
  • Standards must be adapted to project architecture and device targets
  • Engineering and art alignment is critical for memory stability

FAQ

What is the safest memory limit for Unity mobile games?
Typically 50–60% of device RAM based on Android memory pressure behavior.

Why is PSS more important than RSS?
Because it reflects proportional real memory usage instead of overcounting shared libraries.

What causes most Unity memory crashes?
Excessive PSS usage and uncontrolled Native Heap growth.

Why does Unknown memory appear in profiling tools?
It often includes system allocations, IL2CPP memory, or compressed asset bundles.

How can memory issues be reliably diagnosed?
By combining Unity Memory Profiler, adb dumpsys meminfo, and Perfetto tracing.

Why is Mono heap critical?
Because it directly impacts GC pauses and runtime stability.

Should memory limits be fixed across all projects?
No, they must be adjusted based on project type and platform.

How can memory standards be enforced in production?
Through automated asset validation and engineering pipelines (e.g., GameOptim tooling).



Continue reading the series

  1. Why Do Mobile Games Crash, Lag, or Overheat? A Unified Framework for CPU, GPU, and Memory Optimization in Unity
  2. Common Resource Memory Issues in Unity Mobile Games
  3. Why Is Texture Memory So High in Unity Mobile Games?
  4. How Do Vertex Count, Vertex Attributes, and Read/Write Settings Affect Mesh Performance in Unity Mobile Games?
  5. How Can You Reduce Animation Memory Usage and Runtime Overhead in Unity Mobile Games?
  6. How Can You Reduce Audio Memory Usage and Playback Overhead in Unity Mobile Games?
  7. How Can You Reduce Material Count and Avoid Material-Related Performance Waste in Unity Mobile Games?
  8. How Can You Reduce Render Texture Memory Usage and Rendering Overhead in Unity Mobile Games?
  9. What Causes Excessive Shader Memory Usage and Variant Explosion in Unity Mobile Games?
  10. Why Do Font and Particle System Resources Consume Excessive Memory in Unity Mobile Games?
  11. Why Does Mono Heap Memory Keep Growing and Trigger GC Spikes in Unity Mobile Games?
  12. Why Is Memory Usage Still High After Optimizing Unity Resources?
  13. What Defines a CPU Bottleneck in Unity Mobile Games?
  14. Unity Rendering CPU Optimization: Why Is Rendering Time So High?
  15. What Causes UI Performance Bottlenecks in Unity Mobile Games?
  16. Is Unity Physics Wasting CPU Time on Mobile? How to Detect and Reduce Hidden Physics Overhead
  17. Why Is Unity Animation Taking Too Much CPU on Mobile?
  18. How to Reduce Particle System CPU Spikes and Runtime Overhead in Unity Mobile Games?
  19. How Can I Reduce Unity Loading Time and Avoid Runtime Stutters?
  20. How Can I Optimize Unity Logic Code, Lua, and Hotfix Runtime Performance?
  21. How Do I Identify GPU Bottlenecks in Unity Mobile Games?
  22. How can developers accurately determine whether a Unity mobile game is GPU Bound using GPU Clocks?
  23. How can developers identify and optimize GPU vertex-stage bottlenecks in Unity mobile games?
  24. How can developers identify and reduce GPU fragment-stage bottlenecks in Unity mobile games?
  25. How to Reduce Shader Complexity in Unity Mobile Games?
  26. How to Optimize Post-processing in Unity Mobile Games?
  27. How to Reduce GPU Bandwidth in Unity Mobile Games?
  28. Why Does My Unity Mobile Game Overheat, Drain Battery Fast, and Drop FPS After a While?

Top comments (0)