Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
    Bookmark Topic Watch Topic
  • New Topic

Out of memory error while converting string to stream

 
Johny Kk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please UseOneThreadPerQuestion. Let's continue here, as that already has a reply (and memory errors are not specific to I/O).
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!