如何增加的Andr​​oid 2.3(姜饼)堆大小? [英] How to increase heap size on Android 2.3 (Gingerbread)?

查看:197
本文介绍了如何增加的Andr​​oid 2.3(姜饼)堆大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个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类和较新版本的Andr​​oid的唯一版本: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 构造。

或者,找到一个方法来实现不管它是你没有创建一个连续4MB做字符串

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).

解决方案

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.

这篇关于如何增加的Andr​​oid 2.3(姜饼)堆大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆