I am facing java.lang.OutOfMemoryError: Java heap space. Some bulk amount of data converting into toString(). I have my own implementation of toString code. You can see below code:
String dataStr = (new LargeData(objData)).toString();
public String toString()
{
try
{
if (localBase64Binary != null)
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
localBase64Binary.writeTo(out); return out.toString("utf-8");
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
return null;
}
I am using maximum heap space -Xms128m -Xmx256m. If I increase heap space just I can postpone out of memory some days only. Is there any way to optimize the code in this situation?
Can any one please guide me or help me to resolve this issue?
{}tags present in the editor window to format the code.localBase64Binary?