Monday, April 16, 2012

optimize heap size on android

I'm experiencing troubles issue with an android APP running into outOfMemory.

After dig and searching for memory leak, I discover that - I think - problem is that:

  • my initial Heap size is 11 MB (98% used).

  • After calling CAMERA intent, the heap size is increased to 34 MB, 99.5% used (one times crashed cause outOfMemory).

  • After rotating the screen my app goes - sometimes to 52 MB using 70% and sometimes crash with same OutOfMemory.

I read many threads and someone want to increase initial heap size but i read also that should be deprecated soon and it's not a good idea cause increase memory usage even if you don't need it.
Moreover, how can I know how much heap memory my app need? I should still monitor the working and increase time by time with min. step?

My questions is: what is the best way to handle heap size and avoid this kind of outOfMemory exception?

I tried with many version of my code and with samples doing only picture with camera, it's always the same. Just for your reference, this is the posted code

Take picture with android camera (intent) out of memory error

No comments:

Post a Comment