Reference

Trim Memory Levels

Trim memory levels are the TRIM_MEMORY_* constants Android passes to an app's onTrimMemory() callback, signaling how much memory pressure the system is under so the app can release caches, bitmaps, and other reclaimable resources.

Android developmentAndroid

Trim Memory Levels

Also known as: TRIM_MEMORY constants, memory trim levels, android trim memory levels, onTrimMemory levels

Trim memory levels are the TRIM_MEMORY_* constants Android passes to an app's onTrimMemory() callback, signaling how much memory pressure the system is under so the app can release caches, bitmaps, and other reclaimable resources.

  • Delivered via onTrimMemory(int level) using TRIM_MEMORY_* constants.
  • Levels span foreground RUNNING_* states through background BACKGROUND/MODERATE/COMPLETE.
  • Several constants were deprecated in Android 14 (API 34); BACKGROUND remains the dependable signal.

What the levels mean

When the system needs RAM, it calls ComponentCallbacks2.onTrimMemory(int level) on running components and passes one of the TRIM_MEMORY_* constants. The level tells the app both whether it is visible and how urgent the pressure is, so it can shed memory proportionally instead of waiting to be killed.

While the app is in the foreground, the system may send TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_RUNNING_LOW, or TRIM_MEMORY_RUNNING_CRITICAL as available memory tightens. Once the UI is no longer visible, TRIM_MEMORY_UI_HIDDEN arrives, a good cue to drop UI-only resources. As the process moves down the background LRU list the system escalates through TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_MODERATE, and TRIM_MEMORY_COMPLETE — the last meaning the process is among the first to be killed if it does not free memory.

How apps respond

A well-behaved app uses these levels to tier its cleanup. At lighter levels it might trim large in-memory bitmap caches; at TRIM_MEMORY_COMPLETE it releases everything non-essential so the process is cheaper to keep alive. This is the same logic any cache library (such as LruCache) hooks into.

Note that several callbacks were deprecated in Android 14 (API 34): the system no longer delivers UI_HIDDEN, RUNNING_*, MODERATE, or COMPLETE on the newest platforms, leaving TRIM_MEMORY_BACKGROUND as the main reliable signal. Apps should still implement onTrimMemory() for backward compatibility while treating it as advisory rather than guaranteed.

Related terms

Keep reading the reference.

Act on it

Guides and tools for this topic.