Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Android devices use different amounts of heap and footprint for the same app

We have developed NDK prototypes for a simple project. The code is compiled and working on device and in simulator. However when looking in the settings menu on the phones: (Samsung Galaxy Nexus(Android 4.2.2), Samsung Gio(Android 2.3.6)), running the app on the Gio takes a lot more space than when the app is run on the Galaxy Nexus. Also, the following command reports much higher heap allocations for the GIO:

System.out.println(Debug.getNativeHeapAllocatedSize() / 1049L);

We are using a static library for a lot of the functionality. The exact results are:

NEXUS:

  • Footprint (MB) (Java implementation)1.24
  • Footprint (MB) (C++ lib implementation)0.96
  • Memory allocation (MB)(Java implementation) 1.6
  • Memory allocation (MB)(C++ lib implementation) 1.5

GIO:

  • Footprint (MB) (Java implementation)1.19
  • Footprint (MB) (C++ lib implementation)1.71
  • Memory allocation (MB)(Java implementation) 4.6
  • Memory allocation (MB)(C++ lib implementation) 5.5

What is the reason for this difference in Footprint and memory usage?

(Measuring the allocations on an iOS device (C++ lib) yields approximately the same result on a 3GS as on a Galaxy Nexus).

like image 924
David Karlsson Avatar asked Nov 04 '22 00:11

David Karlsson


1 Answers

There are lots of differences between Android 2.x and Android 4. An example is how bitmap memory is managed:

On Android Android 2.2 (API level 8) and lower, when garbage collection occurs, your app's threads get stopped. This causes a lag that can degrade performance. Android 2.3 adds concurrent garbage collection, which means that the memory is reclaimed soon after a bitmap is no longer referenced.

On Android 2.3.3 (API level 10) and lower, the backing pixel data for a bitmap is stored in native memory. It is separate from the bitmap itself, which is stored in the Dalvik heap. The pixel data in native memory is not released in a predictable manner, potentially causing an application to briefly exceed its memory limits and crash. As of Android 3.0 (API Level 11), the pixel data is stored on the Dalvik heap along with the associated bitmap.

Quoted from: http://developer.android.com/training/displaying-bitmaps/manage-memory.html

like image 179
Mattias Isegran Bergander Avatar answered Nov 13 '22 16:11

Mattias Isegran Bergander