Android: how to increase heap size at runtime?

前端 未结 5 1992
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 10:41

I have an image cache in my application which is implemented using SoftReferences. Dalvik starts applications with relatively small heap, and then increases it in case of de

5条回答
  •  抹茶落季
    2020-12-09 10:59

    you can't increase the heap size dynamically.

    you can request to use more by using android:largeHeap="true" in the manifest, but you might not get any more heap size than normal, since it's only a request.

    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

提交回复
热议问题