APK errors

OutOfMemoryError crash

Error text

java.lang.OutOfMemoryError: Failed to allocate a 33177612 byte allocation with 25165824 free bytes and 24MB until OOM

Cause

The app exceeds the memory limit the device gives it. Big images, leaking objects or huge lists are the usual culprits.

Step-by-step fix

  1. Watch memory use with dumpsys meminfo.
  2. Load images at screen size, not full size (Glide, Coil or inSampleSize).
  3. Hunt for leaks such as static references to an Activity or listeners never removed (LeakCanary).
  4. Use RecyclerView and paging for long lists.
  5. largeHeap is only a stopgap; fix the real cause.

Example commands

adb shell dumpsys meminfo com.example.app
adb shell am dumpheap com.example.app /data/local/tmp/h.hprof
# manifest
<application android:largeHeap="true" ...>

How to prevent it

Run LeakCanary in debug and check the memory profile after each big feature.

Author and license: Nibras Code