1

I'm building an app where you have the function to upload a post with an image. When the user picks the image I show a thumbnail of it but when I change the screen orientation I get a memory leak. I managed to get it down to the point where it takes about 25 orientation changes to leak memory but can I completely avoid it?

This is the code I use for the bitmap,

private ImageView miniPicture;
private String imagePath;
private WeakReference<Bitmap> imageBitmap;

....

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
imageBitmap = new WeakReference<Bitmap>(BitmapFactory.decodeFile(imagePath, options));                
miniPicture.setImageBitmap(imageBitmap.get());
Mats Hofman
  • 7,060
  • 6
  • 33
  • 48
  • how are you handling the orientation change? see this question: http://stackoverflow.com/questions/5320599/android-bitmap-recycle-question-do-i-need-to-maintain-all-the-references-of-bitm – bigstones Apr 20 '11 at 20:40
  • I don't do anything more than this with my bitmaps, I used `imageBitmap.get().recyle();` but that didn't help for the memory leaks. – Mats Hofman Apr 21 '11 at 10:18
  • did you solve this? I've been able to prolong the memory leak but can't completely avoid it. Also devices with smaller heaps will most likely crash quicker. – CQM Dec 10 '11 at 20:50
  • no I haven't but by compressing the Bitmap I managed to decrease the amout of crashes – Mats Hofman Dec 11 '11 at 16:35

0 Answers0