I have a repeated Runnable task that performs a setImageResource() every 10 seconds (the resource is a jpeg file). This is the only significant thing happening in the activity.
However, after a few iterations (2-4), the app crashes with the following error:
- VM won’t let us allocate X bytes
- Shutting down VM
I did not expect this. Why isn’t the GC cleaning up previous jpeg bitmaps? How do I avoid crashing the VM?
Thanks.
You have to call recycle on previous bitmaps. Android is allocating memory for image recources and is not freeing it until you call recycle method with your hands.