3

How can i manage the memory for the following situation?

Bitmap bitmap = myBitmapProvider.getBitmap();
myImage.setImageBitmap(bitmap);

Based on my understanding this would cause a memory leak (And yes I am getting out of memory crashes) // I tried the following code but it crasshed the app because the bitmap is in-use by my ImageView, so what is the correct solution\?

bitmap.recycle();
bitmap = null;
aryaxt
  • 76,198
  • 92
  • 293
  • 442

1 Answers1

4

I'm guessing you are either creating a lot of those bitmaps or just one large one. If it is just one large one you should check out this post on downsampling images for displaying on the screen: https://stackoverflow.com/a/823966/317862

If your creating a lot of them maybe check out this article: http://www.senab.co.uk/2011/12/28/image-caching/

Community
  • 1
  • 1
sgarman
  • 6,152
  • 5
  • 40
  • 44