1

I have an Android application running as a privileged system application (apk in /system/priv-app) on an embedded Android device that runs KitKat. The embedded system has 1GB of memory and the application itself looks like it is given around 140MB of heap memory. I'm running into performance issues where GC_FOR_ALLOC is being called constantly as I'm trying to allocate new bitmap images in a RecyclerView (images are loaded with Picasso). This causes a noticeable stutter as you scroll. The device itself (cat /proc/meminfo) has about 350MB of free memory.

Since I have access to the framework code that runs on this device, I'm wondering if there is any way to increase the default amount of memory that is available in the heap? When I run adb shell dumpsys meminfo the application never seems to want to take any more memory.

edit

To those wondering I already have largeHeap=true in the Android manifest and it does not help this situation.

Victor Rendina
  • 1,130
  • 12
  • 19
  • Have you tried running the app with `largeHeap` enabled? Granted, the docs suggest that this is not preferred since at the end of the day; the device has the final say in how much memory it can allocate... https://developer.android.com/guide/topics/manifest/application-element#largeHeap – RMSD Aug 27 '18 at 22:59
  • Yeah sorry forgot to mention largeHeap is enabled. – Victor Rendina Aug 27 '18 at 23:12
  • Ah, then perhaps you can also hunt for some optimization tips also (Perhaps even from the answer below)... I see this is a pretty common problem after some searching: https://stackoverflow.com/questions/27396892/what-are-advantages-of-setting-largeheap-to-true. The first answer deal to with some picasso usage also. – RMSD Aug 27 '18 at 23:18

1 Answers1

0

You can enable the largeHeap attribute in AndroidManifest.xml, just like this one

<application
    android:name="your package name"
    android:icon="@drawable/fab"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:largeHeap="true">

</application>

Furthermore, you can override

onTrimMemory(int level)  and  onLowMemory()

in your own application, and you can do something in these two functions.(I am using glide to load image and there are some api to call)

@Override
public void onTrimMemory(int level) {
    if (level == TRIM_MEMORY_UI_HIDDEN){
        Glide.get(this).clearMemory();
    }
    Glide.get(this).trimMemory(level);
    super.onTrimMemory(level);
}

@Override
public void onLowMemory() {
    Glide.get(this).clearMemory();
    super.onLowMemory();
}
kewei xia
  • 111
  • 1
  • 4