File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java Out of memory error Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Java Out of memory error" Watch "Java Out of memory error" New topic
Author

Java Out of memory error

Johny Kk
Greenhorn

Joined: Oct 23, 2006
Posts: 8
I am getting an OutOfMemoryError from the following method. Please find the method and error below. This method is invoked 1000's of times within the project. So I am confused whether this error is because of the input string size or OR due to recursive invocation.

public static InputStream stringToStream(String inputString) {

InputStream inputStream = null;

try {

InputStream inputStream = new ByteArrayInputStream(inputString.getBytes("UTF-8"));

} catch (UnsupportedEncodingException exp) {

exp.printStackTrace();

}

return inputStream;

}

Exception in thread "Thread-61" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.lang.StringCoding.safeTrim(Unknown Source)
at java.lang.StringCoding.access$300(Unknown Source)
at java.lang.StringCoding$StringEncoder.encode(Unknown Source)
at java.lang.StringCoding.encode(Unknown Source)
at java.lang.String.getBytes(Unknown Source)

Thanks for reading this and will appreciate any inputs or advice.

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8555

Java Addict Crazy on Java wrote:


Please check your private messages for an important administrative matter.

[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
Sona Patel
Ranch Hand

Joined: Mar 30, 2009
Posts: 75
Hi Johny,

OutOfMemory error comes when there are many objects in heap which has occupied almost all the memory. Possible reason is there are many objects which have not been garbage collected.

As i can see in the method, this method is creating InputStream object, and as per your description this method is called many times creating many objects of InputStream. You need to check if all the InputStream object created earlier are still being used. if not then check if they are being set to null or not. Making them null will help the garbage collector. There may be other methods in your code in which such objects are created and not set to null after use.

hope this helps

Regards,
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Java Out of memory error
 
Similar Threads
SQLException on connect
Error whiile using JBoss Tool with eclips
Fresh SDK Install Won't Compile?
Out of memory error while converting string to stream
Jobfuscate