Low Memory

Your application is not alone. It has to share resources with many other applications and also the system as a whole. Consequently, there may be times when there is not enough memory for everyone and in this case, Android will ask applications and applications' components (such as activities or fragments) to tighten their belts.

The ComponentCallbacks interface defines the onLowMemory() API, which is common to all application components. When it is called, a component is basically asked to release objects it does not really need. Typically, your implementation of onLowMemory() would release:

  • Caches or cache entries (for example, LruCache as it uses strong references)
  • Bitmap objects that can be generated again on demand
  • Layout objects ...

Get Pro Android Apps Performance Optimization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.