Q:

RAM usage in Android L vs Kitkat

Here is a strange issue which I found when I was analyzing our android jar's compatibility in lollipop.I'm new to android.I wrote a simple app , which has a single screen and a button and on button press, it calls the methods in jar to perform some server calls.I used adb commands to analyze the memory footprint of the app, 
adb shell dumpsys meminfo <package_name>

And here is the footprint in kitkat,(I did not add rest of the rows, as we would be concerned only in the private dirty column of dalvik heap in the foot print, as that is the RAM allocated exclusively for the app including our own allocations.)
** MEMINFO in pid 876 [XXXXX] **

                   Pss  Private  Private  Swapped     Heap     Heap     Heap
                 Total    Dirty    Clean    Dirty     Size    Alloc     Free
                ------   ------   ------   ------   ------   ------   ------
  Native Heap     3054     3032        0        0     6208     5733      178
  Dalvik Heap     4338     4012        0        0    12756    11514     1242

And here is the footprint in lollipop,
** MEMINFO in pid 201 [XXXX] **

                   Pss  Private  Private  Swapped     Heap     Heap     Heap
                 Total    Dirty    Clean    Dirty     Size    Alloc     Free
                ------   ------   ------   ------   ------   ------   ------
  Native Heap     3412     3360        0        0     5572     5236      335
  Dalvik Heap    10359    10132        0        0    18762    11338     7424

If you compare the dalvik heap in private dirty column in both, kitkat uses around 4MB of RAM and lollipop uses around 10MB of RAM.Its the same app that was executed in both the OS, and the difference in huge.
Couple of questions based on this,

Did anyone of you see this kind of increased memory consumption in lollipop?.
Any idea why is the RAM usage is higher in lollipop?
Is there a tool to visualize the RAM allocations of the app?.

PS: I took heap dump of the app in lollipop and I can see 4.4 MB of memory utilized by android.res.Resources System class objects.I have no idea what could be these resources objects, as neither the app nor the jar has static resources.

A:

Android Lollipop has built in ART(Android Runtime) virtual machine instead of Dalvik vm in case of Kitkat. ART performs transformation of the application's bytecode into native instructions that are later executed by the device's runtime environment .ART works on the concept of ahead of time compilation(AOT) and saves the compiled classes during application installation where as Dalvik works on the principle of Just in time (JIT) compilation and purges the cache of compiled classes once the application exists, and recompile's each class whenever a new instance of the application is started.

Any idea why is the RAM usage is higher in lollipop?

To maintain backward compatibility with existing apps. ART uses the same input bytecode as Dalvik, supplied through standard .dex files as part of APK files, while the .odex files are replaced with Executable and Linkable Format (ELF) executables. Once an application is compiled by using ART's on-device dex2oat utility, it is run solely from the compiled ELF executable; this approach eliminates various overheads involved with JIT compilation, but it requires additional time for compilation when an application is installed, and applications take up slightly larger amounts of space to store the compiled code.

Is there a tool to visualize the RAM allocations of the app?.

cat /proc/meminfo-This will give some memory statistics. In that if you add "memfree + cached" you will get total availible free memory.
dumpsys meminfo-This will give memory info for all current processes
dumpsys meminfo -to dump for a particular process.
Apart from this you can also use Eclipse MAT plugin for analyzing JVM heap contents.

