I have a fairly memory intensive process that can cause the heap size to grow near its limits (like 24 in this case).
However, when that process ends, and the Allocated memory (as listed in the DDMS Heap tool and in a heap dump) is far far lower like 6 or 7.
Despite the Allocated memory being low, and there being a lot of free memory, the heap doesn't seem to come back down.
So even though it says there is plenty of memory available I can still get out of memory errors in this case.
So it begs a couple questions:
Even though the Allocated memory in the Heap tab of DDMS and the heap dumps themselves only show 7mb of memory as allocated is there hidden memory that is not mentioned that is not being garbage collected? If so, how do I track this down?
It seems out of memory errors are based on heap size, not allocated memory size. So is there a way to force the heap size to come back down when it doesn't need to be so high when the memory intensive process is over?
Thanks for your insights.
An out of memory occurs when you are trying to use more memory than the maximum allowed heap size. Note however that Android's GC currently does not defragment the heap and it seems that's the issue you are running into. Your heap may have a lot of memory available, but fragmented in small chunks. If the VM cannot find a chunk big enough for the allocation are you trying to do, an OOME will happen.
Have your tried popping in a System.gc() ?
If you're working with bitmaps, you might want to look at this: http://davidjhinson.wordpress.com/2010/05/19/scarce-commodities-google-android-memory-and-bitmaps/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With