IntelliJ Java IDE
The moose likes Performance and the fly likes java.lang.OutOfMemoryError error. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Performance
Reply Bookmark "java.lang.OutOfMemoryError error." Watch "java.lang.OutOfMemoryError error." New topic
Author

java.lang.OutOfMemoryError error.

Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
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 ]

Bhasker Reddy
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
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.


"I'm not back." - Bill Harding, Twister
Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
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

Joined: Jan 30, 2000
Posts: 18652
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

Joined: Jun 13, 2000
Posts: 176
What is the syntax of using java -Xmx128m.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
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

Joined: Aug 10, 2001
Posts: 3878
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


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
 
 
subject: java.lang.OutOfMemoryError error.
 
Threads others viewed
OutOfMemoryError in java swing application
Memory heap error
Netscape 4 Security Exception
sax parser error
Solaris env
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com