How to increase heap size on Android 2.3 (Gingerbread)?

北城余情 提交于 2019-12-21 23:01:04

问题


I am getting an OutOfMemoryError when I try to create a String larger than 4MB using StringBuilder.append().

As far as I know, StringBuilder doesn't have any limitations regarding size and so doesn't String.

So I searched for "how to increase Android heap size" and as far as I could conclude from this answer and this answer, Gingerbread is the only version in which you have no way of dealing with the heap size, since for earlier versions you use the VMRuntime class and for newer versions android:largeHeap="true" on the Manifest.

Is that assumption correct? What do you do when you're in between VMRuntime and android:largeHeap="true"?

I used Runtime.getRuntime().totalMemory()/1048576 - Runtime.getRuntime().maxMemory()/1048576 to get "5.00 MB allocated of 42.00 MB available" on the device I'm using for tests (Android 2.3.6).


回答1:


Is that assumption correct?

I cannot say whether VMRuntime ever worked. android:largeHeap is definitely something for API Level 11+.

What do you do when you're in between VMRuntime and android:largeHeap="true"?

Find a more memory-efficient way of building your 4MB String, such as by providing a large capacity to your StringBuilder constructor.

Or, find a way to implement whatever it is that you are doing without creating a contiguous 4MB String.



来源:https://stackoverflow.com/questions/26802531/how-to-increase-heap-size-on-android-2-3-gingerbread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!