How to check memory usage with Unity tools
Stay organized with collections
Save and categorize content based on your preferences.
In the Android system, the memory limit threshold for Memory
Limiter (Android 17+) and the benchmark value for memory vital
in Google Play Console is 'anonymous RSS + swap'. This
value represents the physical memory pressure level actually occupied by the
process and is a critical metric that must be monitored for stable app
operation.
Currently, it's difficult to measure memory usage that exactly matches
'anonymous RSS + swap' either at runtime or statically within the Unity Engine.
To address this, this page introduces how to track the 'anonymous RSS +
swap' value with high reliability through approximation using the Unity
Profiler, ProfileRecorder API, and Unity Memory Profiler in a Unity Engine
environment.
Check memory usage at runtime
In Unity, directly measuring Android's exact 'anonymous RSS + swap' memory
usage at runtime without overhead can be challenging. However, you can closely
estimate this value (within ~10% variance) using Unity's built-in Profiler APIs.
Memory allocations that bypass Unity's Memory Manager (e.g.,
NativeMalloc(IntPtr size)) can't be tracked by these APIs.
These APIs might not be supported depending on your Unity version.
Analyze memory breakdown (static analysis)
If high memory usage is detected at runtime, you need to identify where memory
is being consumed. Analyzing memory distribution lets you to eliminate
unnecessary allocations and reduce the game's overall memory footprint.
Unity Memory Profiler
To perform an in-depth memory analysis and optimize your game, use the Unity
Memory Profiler package. To locate the items corresponding to Android OS
'anonymous RSS + swap' usage:
Capture a snapshot using the Unity Memory Profiler.
Open the snapshot and navigate to All of Memory > Resident Memory on
Device.
Calculate the sum of the following items:
Untracked
Android Runtime
Native
Managed
Memory metrics viewable when set to Resident Memory in Unity Memory Profiler
Figure 1. Memory Descriptions are stored in resident memory
The total sum serves as a practical substitute for Android OS 'anonymous RSS +
swap', delivering actionable insights for game memory analysis.
Limitation:
Under heavy memory pressure, the Android OS might compress or swap active
memory pages to free up RAM. Because the Unity Memory Profiler can't track
swapped memory, discrepancies might arise during high memory usage
scenarios.
These features might be limited depending on your Unity version.
The AndroidProcessStats script demonstrates how to use JNI (Java Native
Interface) to link into the Android ActivityManager APIs and provides
functionality to fetch running processes, their importance, and OS-level state.
It also contains lightweight methods to read memory stats directly from the
Linux /proc file system.
The GameMemoryMonitor script shows how to hook this information up for
continuous monitoring and debugging, including how to poll the Android APIs on a
background thread to prevent performance overhead (since using JNI and polling
for memory information can be costly), and how to hook into lifecycle events
like OnApplicationPause to track memory changes when the app is backgrounded
or resumed.
To use these tools, add both scripts to your Assets folder, and attach the
GameMemoryMonitor script to a GameObject in your scene.
More accurate assessment
To verify exact Android OS 'anonymous RSS + swap' values, use
Perfetto. It lets you measure precise system-level
memory usage and thoroughly analyze your game's memory footprint.
Perfetto UI showing anonymous RSS, swap, and their sum query.
Figure 2. The Perfetto UI showing anonymous RSS, swap, and their sum query.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2026年08月28日 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026年08月28日 UTC."],[],[]]