[ Web Proxy ]
URL:
Viewing: https://developer.android.com/games/engines/unity/unity-memory-usage [Back]  [Original]

How to check memory usage with Unity tools  |  Android game development  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]
Send feedback

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.

Method 1: Use the Profiler

You can estimate total memory usage by summing the values returned by the following Profiler APIs:

using UnityEngine;
using UnityEngine.Profiling;

public class MemoryMonitor : MonoBehaviour
{
    public long GetEstimatedMemoryUsageBytes()
    {
        long totalReserved = Profiler.GetTotalReservedMemoryLong();
        long monoHeapSize = Profiler.GetMonoHeapSizeLong();

        return totalReserved + monoHeapSize;
    }
}

Method 2: Use the ProfilerRecorder class

You can track Total Reserved Memory and Gfx Reserved Memory metrics using ProfilerRecorder:

using Unity.Profiling;
using UnityEngine;

public class MemoryMonitor : MonoBehaviour
{
    ProfilerRecorder totalRecorder;

#if DEVELOPMENT_BUILD
    ProfilerRecorder gfxRecorder;
#endif

    private void OnEnable()
    {
        totalRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "Total Reserved Memory");

#if DEVELOPMENT_BUILD
        gfxRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "Gfx Reserved Memory");
#endif
    }

    private void OnDisable()
    {
        totalRecorder.Dispose();

#if DEVELOPMENT_BUILD
        gfxRecorder.Dispose();
#endif
    }

    public long GetEstimatedMemoryUsageBytes()
    {
#if DEVELOPMENT_BUILD
        if (totalRecorder.Valid && gfxRecorder.Valid)
        {
            return totalRecorder.LastValue - gfxRecorder.LastValue;
        }
#else
        if (totalRecorder.Valid)
        {
            return totalRecorder.LastValue;
        }
#endif
        return 0;
    }
}

Limitation:

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:

  1. Capture a snapshot using the Unity Memory Profiler.
  2. Open the snapshot and navigate to All of Memory > Resident Memory on Device.
  3. Calculate the sum of the following items:

    • Untracked
    • Android Runtime
    • Native
    • Managed
    Memory metrics viewable when set to Resident Memory in Unity Memory Profiler [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:

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. [Perfetto UI showing anonymous RSS, swap, and their sum query.] Figure 2. The Perfetto UI showing anonymous RSS, swap, and their sum query.

Send feedback

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-11 UTC.

Need to tell us more? [[["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-11 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page