androidheap-memorynativeshared-memorydalvik

Is shared memory counted while enforcing Dalvik heap limit in Android?


I understand that any application in Android has some allocated memory-

(1) Dalvik VM heap - strict upper limit; device-dependent.

(2) Native heap - no limit. The amount of memory allocated here is not taken into account while enforcing Dalvik heap limit.

Do correct me if I am wrong.

I have a question regarding these-

When two apps are sharing memory in ashmem, is the shared amount of memory taken into account while checking if the Dalvik heap limit is crossed? What I mean is, when the Dalvik heap limit is being enforced, does the shared memory add to the tally?


Solution

  • You are correct -- the Dalvik VM enforces a limit on the managed heap, but there is no fixed limit on native allocations.

    ashmem allocations are not part of Dalvik's managed heap, so are not counted against the manged heap limit.

    The native allocations matter when the kernel's low-memory killer is looking for processes to discard. I don't know if that uses PSS or some other measure to factor in shared memory when computing process usage.