I see my heap growing and I know it will eventually crash on any device since it just keeps growing.
Grow heap (frag case)
is seen throughout the logs
on my phone it will crash the app at 32mb used. Other phones will of course be 16mb, if there are any with that few resources that run android 2.2
Now, I am using recycle()
on my bitmaps, setting things to null, popping items from complex data structures, and using System.gc()
to invoke garbage collection, throughout the app
but, the heap still grows and its a problem... eventually
How do I just force the app to dump resources so that it can continue functioning.
it is usually always the "bitmap vm budget" exceeding, but I am feeling more and more that I just don't have access to the "clear bitmap vm" command
i had also struggled a lot with this issue. there are many a things you can do.
you can call recycle on each bitmap and set them to null.(
bitmap.recycle()
with relaese all the memory used by this bitmap but does not nullify the bitmap object ).you can also unbind the
drawables
associated with layouts as specified in this link.you can convert your
hashmaps
toWeakHashmaps
. so that its memory would get relaesed when system runs low on memory.you can resize all your bitmaps. have a look at this link..
you can override
onLowMemory()
method in activity which gets a call when entire system runs low on memory. you can release few resources there.you can make your objects
SoftReference
orWeakreference
, so that they get released in low memory condition.But the real fact is that, all this can DELAY your out of memory issue/crash, but can not eliminate it because thing is that you must be leaking your activity context or memory somewhere.