开发者

what shoud be difference between "NativeHeapAllocatedSize" and "Runtime totalMemory" in Android to prevent from "OutOfmemory Exception"?

hello i m doing some runtime calculation for getting NativeHeap memory and allocated memory at runtime, so any one can suggest me

what should be the difference between "Debug.getNativeHeapAllocatedSize()" 开发者_开发知识库and "Runtime.getRuntime().totalMemory()"

so can prevent app by OutOf Memory Exception.

Thanks


Runtime.getRuntime().totalMemory()

Returns the total amount of memory which is available to the running program.

getNativeHeapAllocatedSize()

For devices below HoneyComb most of the huge allocations are deferred to the native heap (e.g Bitmaps). Hence this api is useful to find out how much of native heap is allocated.

OOM Errors occurs when there are no objects which can be freed by the DVM. Typically you have about 16MB in the Heap to play with (for a standard phone). Check your logs* to see GC statements having info about how much of memory is allocated.

I don't think there should be a fixed ratio to cause an OOM error. Like in the case when you load a very huge bitmap, here the native memory used is huge.

  • Slide 25
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜