Reference

onLowMemory()

onLowMemory() is an Android callback the system invokes when the whole device is critically low on memory, signaling running apps to release non-essential resources like caches and bitmaps before processes get killed.

Android developmentAndroid

onLowMemory()

Also known as: low memory callback android, android onlowmemory, onLowMemory

onLowMemory() is an Android callback the system invokes when the whole device is critically low on memory, signaling running apps to release non-essential resources like caches and bitmaps before processes get killed.

  • Part of the ComponentCallbacks interface; available on Application, Activity, and Service.
  • Fired only under severe, device-wide memory pressure after background processes are killed.
  • Largely replaced by onTrimMemory(), which gives graduated levels rather than a single signal.

When the system calls it

onLowMemory() is defined on Application, Activity, Service, and other ComponentCallbacks implementers. The framework calls it when background processes have already been killed and the device is still under heavy memory pressure, so the foreground app should free whatever it can to avoid being killed itself.

In modern code it is largely superseded by onTrimMemory(int level), which delivers graduated signals such as TRIM_MEMORY_RUNNING_LOW and TRIM_MEMORY_COMPLETE. onLowMemory() is roughly equivalent to the most severe TRIM_MEMORY_COMPLETE level for a running process, and onTrimMemory is preferred because it lets an app shed memory progressively instead of only at the critical point.

What an app should release

A correct response drops caches and recomputable data: in-memory bitmap and image caches, decoded thumbnails, parsed buffers, and other objects that can be rebuilt later. The goal is to lower the app's footprint quickly so the Low Memory Killer spares it and the user does not see a jank or a restart.

For a storage-cleaner app that scans photo libraries, the scan can hold many decoded thumbnails and perceptual-hash buffers in memory at once. Handling onLowMemory() (and onTrimMemory) by clearing those caches keeps the scan from being killed mid-run on lower-RAM devices, then the data is lazily reloaded as the user scrolls results.

Related terms

Keep reading the reference.

Act on it

Guides and tools for this topic.