Why is Appsi using so much memory

First of all, it has to do with how memory management works on modern operating systems like linux (on which Android is running).

The most important thing to remember: Memory can be shared between multiple applications, and this causes both apps to use that memory.

For example when gathering the memory info of the appsi powerpack, it may look something like this:

** MEMINFO in pid 27574 [com.appsimobile.appsipowerpack] **

Shared Private Heap Heap Heap

Pss Dirty Dirty Size Alloc Free

------ ------ ------ ------ ------ ------

Native 0 0 0 64380 57443 1072

Dalvik 3856 5616 3608 10776 4653 6123

Stack 28 8 28

Cursor 0 0 0

Ashmem 0 0 0

Other dev 4 28 0

.so mmap 653 2756 484

.jar mmap 0 0 0

.apk mmap 30534 0 0

.ttf mmap 0 0 0

.dex mmap 1147 0 0

Other mmap 25 8 8

Unknown 51383 6168 51144

TOTAL 87630 14584 55272 7515662096 7195

Android will report the amount of used memory to be somewhere around 75MB (75156 in bold). When taking a memory snapshot of the app (dumping the hprof) it will show the privately allocated memory withing dalvik. And these values may differ a lot

According to the memory dump the Powerpack plugin is only using 2.4MB of memory.

So how can we explain this extreme difference?

Well, Appsi and it's plugins access several system resources. The first memory dump only shows the top part, there's also a part about asset allocations that looks like this:

Asset Allocations

zip:/system/framework/framework-res.apk:/resources.arsc: 5604K

zip:/system/app/Mms.apk:/resources.arsc: 969K

zip:/system/app/Settings.apk:/resources.arsc: 6687K

zip:/system/app/Gallery2.apk:/resources.arsc: 1045K

zip:/system/app/Browser.apk:/resources.arsc: 1034K

zip:/system/app/Calculator.apk:/resources.arsc: 112K

zip:/system/app/Contacts.apk:/resources.arsc: 1087K

zip:/system/app/DeskClock.apk:/resources.arsc: 789K

zip:/system/app/Dialer.apk:/resources.arsc: 828K

zip:/system/app/Email.apk:/resources.arsc: 1237K

zip:/system/app/GmsCore.apk:/resources.arsc: 3531K

zip:/system/app/Hangouts.apk:/resources.arsc: 2929K

zip:/system/app/DSPManager.apk:/resources.arsc: 210K

zip:/system/app/DownloadProviderUi.apk:/resources.arsc: 93K

zip:/system/app/ParanoidOTA.apk:/resources.arsc: 47K

zip:/system/app/QuickSearchBox.apk:/resources.arsc: 4827K

zip:/system/app/SoundRecorder.apk:/resources.arsc: 50K

zip:/system/app/Torch.apk:/resources.arsc: 52K

zip:/system/app/VideoEditor.apk:/resources.arsc: 383K

It appears that all these resources count as memory used by the powerpack plugin as well. This adds roughly 30MB to the memory usage.

This accounts for the 30,534K of pss in the apk mmap. Now also take a look at this line:

Unknown 51383 6168 51144

Something else is also adding about 50MB to the memory usage. My best guess is that these are resources from other apps used by the powerpack plugin, for example to load calendar data, read settings status (the toggles for example) and the list of recent Apps. The powerpack plugin connects to all kinds of resources to gather this information that count against its own memory usage as well.

The same goes for Appsi, it connects to the Android PackageManager to get info about installed apps, it connects to home plugins and DashClock extensions, it may host app widgets that connects Appsi to the AppWidgetManager (across multiple apps). All these things may add up to the memory usage you see in Appsi.

For more information (and details how to interpret the different values) see this answerby Dianne Hackborn to a similar question on stackoverflow.com.