Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum size of native heap on Android?

If I have understood correctly, an android process has two heaps - one managed by the VM and one native.

The size of the VM heap cannot exceed 16mb (at least, this value can be higher on some phones).

But what about the maximum size of the native heap?

The 16 mb limit doesn't seem to be a hard limit in that an app can allocate more than 16mb through the NDK, but the OS will start killing other processes and possibly the foreground process as well when a high amount of memory is used.

When does the OS start behaving this way? When the native heap + VM heap size exceeds 16mb?

Debug.getNativeHeapSize() gives the size of the native heap, but is there a function to check the combined native + VM heap size?

Curious to hear from someone who knows how this works!

like image 811
Viktor Avatar asked May 04 '11 08:05

Viktor


People also ask

What is Android heap size?

By default, Android Studio has a maximum heap size of 1280MB. If you are working on a large project, or your system has a lot of RAM, you can improve performance by increasing the maximum heap size for Android Studio processes, such as the core IDE, Gradle daemon, and Kotlin daemon.

What is native heap in Android?

Very quickly: The heap memory is the memory allocated to the java process by the -xMx parameter whereas the native memory is the memory available to the OS.

Is there a limit on the heap?

There's no limit on heap size, program usually have all of the available virtual address space.

How much memory can an Android app use?

Early Android devices had a per-app cap of 16MB. Later this cap increased to 24MB or 32MB.


1 Answers

There is no "line of death" in Android memory management. When the system needs to kill processes to reclaim memory, it considers a number of different factors, including the process' importance (determined by factors like whether or not it's in the foreground, or providing services to a foreground app) and how much memory it's using.

If your process is idle, and sitting on more memory than anything else, it's likely to be killed first.

The exact algorithm has evolved a bit over time, and the system doesn't make any guarantees about specific behavior.

like image 84
fadden Avatar answered Sep 21 '22 22:09

fadden