如何增加的Android 2.3(姜饼)堆大小? [英] How to increase heap size on Android 2.3 (Gingerbread)?
问题描述
我得到一个OutOfMemoryError,当我尝试创建一个字符串
使用4MB相比较大 StringBuilder.append()
据我所知,的StringBuilder
没有任何限制有关尺寸等不字符串
所以,我搜索如何增加Android的堆大小而据我可以从<一个结论href=\"http://stackoverflow.com/questions/11275650/how-to-increase-heap-size-of-an-android-application\">this回答和<一个href=\"http://stackoverflow.com/questions/7598835/alternative-of-vmruntime-getruntime-setminimumheapsize-in-gingerbread\">this回答,姜饼是在你没有对付堆大小的方式,因为早期版本使用VMRuntime类和较新版本的Android的唯一版本:largeHeap =真
的清单。
是假设是正确的?当你在VMRuntime之间是你做什么和的android:largeHeap =真正的
我用调用Runtime.getRuntime()totalMemory()/ 1048576 - 调用Runtime.getRuntime()maxMemory()/ 1048576
来得到5.00 MB分配42.00 MB。可用我使用的测试(Android版2.3.6)在设备上。
是假设是正确的?
块引用>我不能说
VMRuntime
是否工作过。的android:largeHeap
绝对是东西API级别11 +
做什么,当你在VMRuntime和Android之间是你做的?largeHeap =真正的
块引用>查找构建4MB
字符串
,如您的StringBuilder $ C $提供了大容量的内存更有效的方法C>构造。
或者,找到一个方法来实现不管它是你没有创建一个连续4MB做
字符串
。I am getting an OutOfMemoryError when I try to create a
String
larger than 4MB usingStringBuilder.append()
.As far as I know,
StringBuilder
doesn't have any limitations regarding size and so doesn'tString
.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).解决方案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 yourStringBuilder
constructor.Or, find a way to implement whatever it is that you are doing without creating a contiguous 4MB
String
.这篇关于如何增加的Android 2.3(姜饼)堆大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!