Hi, please read this: http://www.javamex.com/tutorials/memory/string_saving_memory.shtml
substring() on a String does NOT create a new smaller String, but creates a smaller view on the full-size char-array of the original String. This has the consequence, that the original char-array is still referenced and is not garbage collected. Use setValue( new String( bigString.substring(x,y) ) ) to force creation of a new instance and allow release of the full String. I found this out recently, when I ran into the same problem with my custom HTML Parser. Regards, Rafael On 20 Feb., 15:00, vijay kumar <[email protected]> wrote: > 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 memoryerror .I am getting > value like <>& like characters are coming in webservice .can > any body tell how to avoid that out of memeory error ? > > my code to replace > > 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 < len; ++i) { > char c = str.charAt(i); > if (c == '&') { > int pos = str.indexOf(";", i); > if (pos == -1) { // Really evil > buf.append('&'); > } 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("&")) > buf.append('&'); > else if (substr.equals("<")) > buf.append('<'); > else if (substr.equals(">")) > buf.append('>'); > else if (substr.equals(""")) > buf.append('"'); > else if (substr.equals("'")) > buf.append('\''); > else if (substr.equals(" ")) > buf.append(" "); > > else > // ???? > buf.append(substr); > i = pos; > } > } else { > buf.append(c); > } > } > return buf.toString(); > } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

