Why does my application have less heap memory than others?

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

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

Yes, it is large enough, but task management tools claim that my application uses only 30 MB of memory, while others use 50 MB and even 110 MB (seen once) at the same time, and there are still 190 MB of free memory in the system (not system applications, just other regular applications that I installed). If at startup all applications have the same heap size, how can they grow so large?

+3
source share
3 answers

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

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

You can query the memory class for each application using ActivityManager.getMemoryClass(), which appears to be a shape that is not at all related to heap size.

Applications can use memory that is not on the heap, but 100 + MB seems surprisingly large.

Android, , Dianne Hackborn, Android Google. , , , .

+4

? .

-Xms Java  -Xmx Java

java -X

: java -Xms20m -xMX100m -cp. MyMain

.

-1

We all know that java has a garbage collector by default, but at some level we need to clean or photograph some object.

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

-1
source

Source: https://habr.com/ru/post/1775682/


All Articles