Software⏱️ 2 min read📅 2026-05-30

How to Fix: Android:java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM

Android OutOfMemoryError: Failed to allocate a large byte allocation with limited free bytes and memory until OOM. Solution involves optimizing image handling, reducing bitmap size, or using alternative image loading methods.

Quick Answer: Optimize image handling by reducing bitmap size, using alternative image loading methods (e.g., using InputStreams), or implementing lazy loading to prevent excessive memory allocation.

The OutOfMemoryError in Android is usually caused by the excessive memory usage of the application. In your case, it's likely due to the large size of the image stored on the SD card.

✅ Best Solutions to Fix It

Method 1: Reduce Image Size

  1. Step 1: Use a library like Android Image Compression Library to compress the images before storing them on the SD card.

Method 2: Load Images in Memory Wisely

  1. Step 1: Use a BitmapFactory to load images in memory, and use the scaledBitmap method to reduce the image size.

💡 Conclusion

By implementing these methods, you can significantly reduce the memory usage of your application and avoid the OutOfMemoryError.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions