• Post Reply Bookmark Topic Watch Topic
  • New Topic

Out Of Memory Exception  RSS feed

 
Senthil Kumar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
My task is to check the file contents with the format which is defined in XML.
so,initially i used DOM Parser and the following code.
File file = new File("c:\sample.txt"); // sample.txt has >20,00,000 lines
FileReader fileReader = new FileReader(file);
BufferedReader = new BufferedReader(fileReader);
String contents;
while((contents=br.readLine())!=null){
process(contents) //Method that will parse the XML and compare with the contents
}

I get the above mentioned Exception.
I thought it might be because of DOM Parser.so,i changed to SAX Parser.even then i have the same exception.
But,when i just print the contents of the file without calling the method process().I don get this exception.

NOTE : I tried giving [B]-Xmx**m.i need to giv different values for the heap memory and that is not allowed.[/B]

Can anyone provide me a solution?

Thanks in advance
Senthil
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just reading through a file, however large, will not consume much memory. So we can conclude it is what your process() method does that consumes the memory. As you have given minimal information about process(), there is little advice that can be given.

Switching from DOM to SAX will generally use less memory, since DOM stores an element tree representing the whole XML document and SAX doesn't - well, not in itself, but SAX handlers often create a tree. We can't see your handler, so we don't know.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!