Dalvik-vm Out Of Memory while appending string with StringBuilder
<p>My App receives image data from server as XML. During paring the XML, I append the data using StringBuilder, decode the image data and then display the image. If the image size is greater than 1MB, I get Dalvik-vm "Out Of Memory' exception as below:</p>

<pre><code>07-16 19:23:35.376: E/dalvikvm-heap(374): Out of memory on a 10501076-byte allocation.
07-16 19:23:35.376: I/dalvikvm(374): "AsyncTask #2" prio=5 tid=10 RUNNABLE
07-16 19:23:35.376: I/dalvikvm(374):   | group="main" sCount=0 dsCount=0 obj=0x405e3238 self=0x38ff88
07-16 19:23:35.376: I/dalvikvm(374):   | sysTid=434 nice=10 sched=0/0 cgrp=bg_non_interactive handle=3735744
07-16 19:23:35.376: I/dalvikvm(374):   | schedstat=( 3989536323 3728953745 437 )
07-16 19:23:35.376: I/dalvikvm(374):   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~95)
07-16 19:23:35.376: I/dalvikvm(374):   at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:153)
07-16 19:23:35.376: I/dalvikvm(374):   at java.lang.StringBuilder.append(StringBuilder.java:217)
07-16 19:23:35.376: I/dalvikvm(374):   at os.android.lib.asgsuitesdk.XmlReader.characters(XmlReader.java:121)
07-16 19:23:35.376: I/dalvikvm(374):   at org.apache.harmony.xml.ExpatParser.text(ExpatParser.java:165)
07-16 19:23:35.376: I/dalvikvm(374):   at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
07-16 19:23:35.376: I/dalvikvm(374):   at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:518)
07-16 19:23:35.376: I/dalvikvm(374):   at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
07-16 19:23:35.376: I/dalvikvm(374):   at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318)
07-16 19:23:35.376: I/dalvikvm(374):   at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
07-16 19:23:35.376: I/dalvikvm(374):   at javax.xml.parsers.SAXParser.parse(SAXParser.java:390)
</code></pre>

<p>Is there anyway, I can get rid of this exception? I know, depends on the device, the heap memory allocated for an Android app is minimum 16MB. In my case, the image size is between 1MB ~ 2MB and it crashes. Any help is highly appreciated.</p>

<p>Thanks,
DK</p>
