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