Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative of VMRuntime.getRuntime().setMinimumHeapSize in Gingerbread

Tags:

java

android

I know there's a VMRuntime.getRuntime().setMinimumHeapSize in Android 2.1/2.2 for developer to adjust the starting heap size of the application, and it is one of the most effective solution sfor solving the OutOfMemory error during BitmapFactory.decodeStream()

However, since Android 2.3, this VMRuntime class is removed from official API, does anyone knows the alternative API of this function in 2.3?

like image 502
qichuan Avatar asked Sep 29 '11 14:09

qichuan


2 Answers

and it is one of the most effective solution sfor solving the OutOfMemory error during BitmapFactory.decodeStream()

Really? Setting the minimum heap size may reduce GC churn, but I would love to see links to places where it helped with OutOfMemoryErrors.

However, since Android 2.3, this VMRuntime class is removed from official API, does anyone knows the alternative API of this function in 2.3?

There is none. That behavior is no longer exposed.

like image 166
CommonsWare Avatar answered Nov 16 '22 22:11

CommonsWare


you can't increase the heap size dynamically.

you can request to use more by using android:largeHeap="true" in the manifest.

also, you can use native memory, so you actually bypass the heap size limitation.

here are some posts i've made about it:

  • How to cache bitmaps into native memory

  • JNI bitmap operations , for helping to avoid OOM when using large images

and here's a library i've made for it:

  • https://github.com/AndroidDeveloperLB/AndroidJniBitmapOperations
like image 41
android developer Avatar answered Nov 16 '22 23:11

android developer