• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Out Of Memory Exception

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic