Reputation: 3335
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!
Upvotes: 12
Views: 4868
Reputation: 52343
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.
Upvotes: 4