开发者

Why my application has less heap memory than others?

My question may look naive but I do not know how to formulate it more correctly. The problem is that I create and use large simple type arrays in my application. And I get errors like:

ERROR/dalvikvm-heap(1763): Out of memory on a 7907344-byte allocation.

Yes, it's big enough but task management tools claim that my application is using only 30MB of memory, while other at the same time use 50MB and even 110MB (have seen once) and there is still 190MB of free memory in the system (not system applications, just other ordinary applications I have installed). If all applications are provided with the same heap size at startup how can the开发者_如何转开发y grow so big?


The maximum heap size of an Android application will depend on the device it is running on. For early devices the maximum heap size was 16MB but for some later devices it can be 24MB or possibly even 32MB.

This is a property of the Dalvik VM on each device and is not something you can change (without rebuilding Android from source).

You can query the "per-application memory class" with ActivityManager.getMemoryClass() which seems to be a figure which is not entirely unrelated to the Heap Size.

Applications can use memory which isn't on the heap but 100+MB seems like a surprisingly large amount.

If you want to find out about analysing memory usage on Android you can't do better than this Stack Overflow answer by Dianne Hackborn, who is one of the Android developers at Google. In short it says analysing memory usage is very difficult and you should take any figures you have with a pinch of salt.


Did you try to configure your heap size? Use the following options to do this.

-Xms set initial Java heap size -Xmx set maximum Java heap size

To obtain more help run java -X

Example: java -Xms20m -xMX100m -cp . MyMain

Good luck.


We all know that java has by default garbage collector system but at some level we need to clear or flush some object.

And you also can set or configure heap size for the JVM.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜