How to avoid out of memory error in android
<p>Hi friends
I am getting the value from webservice while unescape xml value .I am storing in stringBuffer . I am getting the lot of value from webservice .so I am getting out of memory error .can any body tell how to avoid that?</p>

<p>My UnescapeXml code</p>

<pre><code>public  String unescapeXML(String str) {
            if (str == null || str.length() == 0)
              return "";

            StringBuffer buf = new StringBuffer();
            int len = str.length();
            for (int i = 0; i &lt; len; ++i) {
              char c = str.charAt(i);
              if (c == '&amp;') {
                int pos = str.indexOf(";", i);
                if (pos == -1) { // Really evil
                  buf.append('&amp;');
                } else if (str.charAt(i + 1) == '#') {
                  int val = Integer.parseInt(str.substring(i + 2, pos), 16);
                  buf.append((char) val);
                  i = pos;
                } else {
                  String substr = str.substring(i, pos + 1);
                  if (substr.equals("&amp;amp;"))
                    buf.append('&amp;');
                  else if (substr.equals("&amp;lt;"))
                    buf.append('&lt;');
                  else if (substr.equals("&amp;gt;"))
                    buf.append('&gt;');
                  else if (substr.equals("&amp;quot;"))
                    buf.append('"');
                  else if (substr.equals("&amp;apos;"))
                    buf.append('\'');
                  else if (substr.equals("&amp;nbsp;"))
                      buf.append(" ");

                  else
                    // ????
                    buf.append(substr);
                  i = pos;
                }
              } else {
                buf.append(c);
              }
            }
            return buf.toString();
          }
</code></pre>

<p>Thanks</p>
