java.lang.OutOfMemoryError with DOM

I am trying to test different parsers, i have problem with DOM when i try to parse 70 MB xml file. Error is java.lang.OutOfMemoryError I think i have decent computer, so i am not sure there is problem.

another question. I am using stopwatch to catch parsing time, but i guess that i put stopwatch.stop on wrong place. i guess it suppose to be right after

Document document = builder.parse("file.xml"); 

i have put it after for loop which prints out all nodes



Common problem if you're using the default heap size and parsing large XML documents. You will need to increase the Heap size of the JVM. When executing your program add the argument "-Xmx1024m" (or -Xmx512m or whatever it is you think you need, the heap will only take up as much memory as it needs up to the point specified) to the jvm command.

example: java -Xmx1024m -jar myprogram.jar

this can also be set in the runtime properties of various IDEs. In eclipse, it is the "VM arguments" section of the Run Configuration for your application.

The solution depends on which type of java.lang.OutOfMemoryError did you receive. If it was a PermGen space you need to add the following parameter to the JVM to set the PermGen (in the example it will set to 300 MB):


If it is a Java Heap Space add this parameter to set the Heap space (in this case 1 GB):


Also, if you will be processing large XML documents, you may want to try a different approach. The deciding factor is whether you need the entire document in memory at the same time. To conserve space you can parse in portions of the XML separately.

This is called a streaming XML parser. You will want to Google some different streaming XML parsers for Java. The first thing that comes to mine is StAX, which is the spec. A common util is Apache Axiom.

Need Your Help

Accessing method transform.Rotate in user-built class?

c# unity3d

I'm studying C# and Unity3D with "Learning C# by Developing Games with Unity #D Beginner's Guide" by Terry Norton and I'm blocked with an error.