I am downloading an image from an ip-webcam several times in a second and assign it by using setImageBitmap to an ImageView object.
try {
final Bitmap image = downloadBitmap();
if (image != null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
ImageView imageView = (ImageView) view.findViewById(R.id.imageView1);
if (imageView != null) {
imageView.setImageBitmap(image);
}
/* Try to get rid of the GC_FOR_ALLOC: */
//image.recycle();
//System.gc();
//Runtime.getRuntime().gc();
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
But the logcat is "exploding" by showing
03-30 12:15:55.059: D/dalvikvm(19846): GC_FOR_ALLOC freed 186K, 7% free 50113K/53856K, paused 30ms, total 31ms
03-30 12:15:56.069: D/dalvikvm(19846): GC_FOR_ALLOC freed 65K, 7% free 53713K/57460K, paused 27ms, total 27ms
03-30 12:15:57.099: D/dalvikvm(19846): GC_FOR_ALLOC freed 94K, 7% free 57349K/61064K, paused 27ms, total 27ms
03-30 12:15:58.129: D/dalvikvm(19846): GC_FOR_ALLOC freed 124K, 6% free 60940K/64668K, paused 67ms, total 67ms
I tried to recycle the Bitmap image:
image.recycle();
System.gc();
Runtime.getRuntime().gc();
But that causes an exception if the ImageView is getting drawn again:
**03-30 12:15:53.109: E/AndroidRuntime(19846): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@42e1bfb8
Does someone got an idea on how to get rid of the GC_FOR_ALLOC messages in logcat?
Best regards, Juergen