Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

android - Out of memory errors occur with a high heap size but low allocated size. Why?

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:

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

  2. 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...