I'm working with Gallery-widget and a lot of bitmaps. For erasing bitmaps I use Bitmap.recycle(). As result I see on logcat next messsage:
08-18 17:49:26.020: INFO/dalvikvm-heap(13847): Grow heap (frag case) to 22.373MB for 2457616-byte allocation
08-18 17:49:26.060: DEBUG/dalvikvm(13847): GC_FOR_ALLOC freed 1K, 36% free 22835K/35143K, paused 27ms
08-18 17:49:26.230: DEBUG/dalvikvm(13847): GC_CONCURRENT freed <1K, 36% free 22835K/35143K, paused 2ms+3ms
08-18 17:49:28.070: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.080: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.110: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.120: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.140: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.160: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.180: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.190: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.210: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.230: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.240: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.260: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.280: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.290: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.310: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.330: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.350: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.360: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.380: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.400: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.410: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.430: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.450: ERROR/OpenGLRenderer(13847): Cannot generate texture from bitmap
08-18 17:49:28.500: INFO/System.out(13847): Image width: 144; height: 108
08-18 17:49:28.570: DEBUG/dalvikvm(13847): GC_FOR_ALLOC freed 4094K, 42% free 20449K/35143K, paused 27ms
08-18 17:49:28.620: INFO/dalvikvm-heap(13847): Grow heap (frag case) to 22.385MB for 2457616-byte allocation
And item on Gallery-widget is black. But application works.
Have you any idea for this question?
This also happens when we reuse a bitmap
Eg.bitmap=getResizedBitmap(bitmap,500); Here I have used bitmap again to resize it, which caused an issue.
I just had the same problem. The thing is that by calling recycle() you destroy native object referencing to the pixel data of the image and the object itself (bitmap) is marked "dead". If there is no other object referencing to those data they will be freed by GC. So two possible thing are happening to you:
So if you're using/referencing this bitmap and you recycle it, you simply deny access to it for everybody. At least I understand it this way. Read this carefully:
http://developer.android.com/reference/android/graphics/Bitmap.html#recycle%28%29
So you should use recycle only if you're sure that no one is using/referencing the bitmap object. I hope it helps.
As speedy said, you are probably trying to access bitmaps that have been marked for Garbage Collection.
A simple solution for this is to do an
isRecycled()
check before returning a bitmap: