java.lang.OutOfMemoryError – BitmapFactory.decode(strPath)

You need to recycle Bitmap object .

    Bitmap bm = BitmapFactory.decodeFile(strPath);
    imageView.setImageBitmap(bm);

After above lines of code in your get view just add the code written below
///now recycle your bitmap this will free up your memory on every iteration

    if(bm!=null)
   {
     bm.recycle();
     bm=null;
    }

After this also if you are getting same error the

Replace below code

    Bitmap bm = BitmapFactory.decodeFile(strPath);
    imageView.setImageBitmap(bm);

with

 final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;

Bitmap bm = BitmapFactory.decodeFile(strPath,options);
imageView.setImageBitmap(bm);

Use inSampleSize to load scales bitmaps to memory. Using powers of 2 for inSampleSize values is faster and more efficient for the decoder. However, if you plan to cache the resized versions in memory or on disk, it’s usually still worth decoding to the most appropriate image dimensions to save space.

For more see Loading Large Bitmaps Efficiently

Leave a Comment