I have a question regarding Memory Leak. The below mentioned JSP code can generate any Out of memory exception

String str = tempStrView.getSTR();
String newStr = str+"'";
String rpcStr = " ";
String convStr = newStr.replaceAll("'",rpcStr);

Thanks in advance,


Can you give an example string that generates a OOM Exception?

Value of str will be a 16 digit number. For eaxmple

String str = 1234567887654321

Are you converting it to a number at any point or are you keeping is as a string throughout the program?

It is a String declaration through out the program. Its used for export the values to excel. 16 digit number will not export properly to excel . SO i have added ' and replacing the ' with blank space. Its working fine after this change. But this application showing out of memory exception some times.

If you are working exclusively wrt manipulating strings, use StringBuilder class for appending operations rather than concatenation for strings. If you still face memory issues, then they might just be valid reasons and would require you to set the heap size accordingly. What is your current heap size?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.