Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.OutOfMemoryError error.  RSS feed

 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running a parsing program which opens 3 threads, each thread parses multiple files(2 files right now). I am getting java.lang.OutOfMemoryError. I am not sure why I am getting this. I am running this java parser on Windows NT with 256 MB RAM. Is it because of small memory size, am I facing this Issue. Is there any way to improve this situation. I am getting this error especially at java.io.InputStreamReader class,when I am trying to read the file.

java.lang.OutOfMemoryError
at java.io.InputStreamReader.<init>(InputStreamReader.java, Compiled Code)
at java.io.FileReader.<init>(FileReader.java, Compiled Code)
[ February 14, 2003: Message edited by: Bhasker Reddy ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange. How big are the files you're reading? Though that should really only be an issue if you've been trying to read all the contents into memory (e.g. a really big StringBuffer, char[] array, or List of Strings).
When you say you've got 256MB - have you actually used java -Xmx to increase the maximum heap size? If not, your max memory is probably 64 MB by default. Experiment with changing this. E.g. use
java -Xmx128m MyClass
to run with max heap size 128 MB.
Does the OutOfMemoryError always come from the same line? Even if you vary the heap size? That would be particularly strange - perhaps you should show us some of the code that ends up calling the FileReader.
 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The files I am reading are 45MB. I am using
BufferedReader in = new BufferedReader(new FileReader(file)); to read the file.
I am parsing all the file and holding the data in an object.(all parsed file). It is crashing at that object level
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well then, it certainly sounds possible you'll need more than the 64 MB the JVM allocates by default. So try changing the -Xmx setting if you haven't already. Though it's strange that your program seems to error in the InputStreamReader constructor - that part doesn't seem very memory intensive.
 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the syntax of using java -Xmx128m.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you're starting your program with something like
java MyClass
you just add the option:
java -Xmx128m MyClass
as I showed in my first post. If you don't use the "java" command directly (say, if you're using an IDE which hides it) then you may have to find the JVM configuration options on the IDE.
Documentation for the java command and its options can be found
here.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I ask what *kind* of files you are parsing and what kind of parser you are using? For instance, if you are trying to parse a 45 MB XML file with a DOM parser, you've probably generated close to 400 MB of Java objects to represent the file...this is one of the reasons I really don't like DOM...
Kyle
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!