3

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

trincot
  • 317,000
  • 35
  • 244
  • 286
CQM
  • 42,592
  • 75
  • 224
  • 366

1 Answers1

16

i had also struggled a lot with this issue. there are many a things you can do.

  1. 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 ).

  2. you can also unbind the drawables associated with layouts as specified in this link.

  3. you can convert your hashmaps to WeakHashmaps. so that its memory would get relaesed when system runs low on memory.

  4. you can resize all your bitmaps. have a look at this link..

  5. you can override onLowMemory() method in activity which gets a call when entire system runs low on memory. you can release few resources there.

  6. you can make your objects SoftReference or Weakreference, 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.

Community
  • 1
  • 1
N-JOY
  • 10,344
  • 7
  • 51
  • 69
  • 1
    the heap grows when I call camera.takePicture, in between that callback and my savephoto asynchronous task. I've looked for everything to free up, but what it really comes down to is that built in take picture button – CQM Dec 05 '11 at 07:22
  • 1
    you might be leaking memory somewhere else. – N-JOY Dec 05 '11 at 07:27
  • I have one activity, how would I be leaking the context? every place where I close that activity I use System.exit(0) to really make sure its closed – CQM Dec 05 '11 at 16:42
  • leaking context does not mean your activity does not stops/closes completely. i think you might have taken some static variable/objects which does not gets destroyed.(as they are stored on heap). but these are just guesses... – N-JOY Dec 06 '11 at 06:25