2

I have a problem with my XML parser. I need to read and parse a 433kb XML-file and for that, I have written 2 java classes. One class uses SAX and the other JDOM2.

To test, if my class can read the file, I started of by only printing out the root-nodes name.

The problem? Not enough heap space.

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.jdom2.input.sax.SAXBuilderEngine.build(SAXBuilderEngine.java:217)
at org.jdom2.input.sax.SAXBuilderEngine.build(SAXBuilderEngine.java:277)
at org.jdom2.input.sax.SAXBuilderEngine.build(SAXBuilderEngine.java:264)
at org.jdom2.input.SAXBuilder.build(SAXBuilder.java:1116)
at xmlparser.version.one.ReadXML.main(ReadXML.java:20)

I already read a lot of ideas on stackoverflow and other platforms and used them.

So far I have made sure, that my eclipse uses the 64bit JRE, I have made sure my environment-variables point to the 64bit JRE. I also tried to extend the maximum memory available to eclipe in the eclipse.ini. I have tried setting the available memory for the class itself to this: -Xms512M -Xmx1024M Though 1024M is not enough. so I need to set it to 2048, preferable to 4096 just to be sure.

It still doesn't work, now it gives me this error:

Error occurred during initialization of VM Could not reserve enough space for object heap

I have a 64bit System, i3 dual-core with 16GB DDR3 RAM of which at this moment 11.2GB are available.

I am out of ideas, can anyone help?

3
  • 433 kilobyte file? Then you have either a leak or a badly malconfigured JVM. Commented Jul 19, 2014 at 12:08
  • Can you provide the code you are using to parse this? Also what Operating system are you using? Commented Jul 19, 2014 at 12:41
  • I would not prefer to reveal my code, it is filled with information I am not allowed to reveal. but I can post the guides I used: mkyong.com/java/how-to-read-xml-file-in-java-sax-parser newthinktank.com/2012/06/java-video-tutorial-44 As for my operating system, I use windows 8.1 64bit Commented Jul 19, 2014 at 13:06

2 Answers 2

1

you can increase your heap size

java -Xmx2g myprogram

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

I already tried this, the second error occurs when I exceed 1024m.
so probably your computer doesnt have enough memory for this file
64 bit jdk should be able to exceed 1024. Are you sure that you are using 64bit jdk?
As I also stated in my question, I have 16 GB memory of which >10 are free.
@Thomas: Thanks for the advice. I am pretty sure, I had the 64bit version of the JDK1.7, I made sure, I use 64bit versions when I installed necessary software on my PC. But your idea brought another idea to me: upgrading to JDK1.8 an now it works. So either the new installation of the JDK made the difference or I made the mistake using the 32bit JDK1.7 when I installed it the first time. It works now, thanks for the push in the right direction.
0

Try using StAX to parse the xml. StAX is a streaming api that allows you to "pull parse" the xml so that the entire document does not have to be read into memory

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.