XMLReader : java.lang.OutOfMemoryError: Java heap space
866911Jun 6 2011 — edited Jun 8 2011I'm using a XMLReader object to Parse XML files. About 20000 XML documents need to be parsed, so the parse(...) method is called about 20000 times in a loop.
The XML string to be parsed are all about 2500 bytes long. Java 1.5 is used.
import java.io.StringReader;
import org.xml.sax.XMLReader;
private final XMLReader parser;
private StringReader stringReader;
public void myParseMethod(final String xml) {
try {
stringReader = new StringReader(xml);
parser.parse(new InputSource(stringReader));
stringReader.close();
} catch (final SAXParseException e) {
} catch (final SAXException e) {
} catch (final IOException e) {
}
Calling the method myParseMethod(final String xml) goes well till about 2000 times. Then the following exception is thrown:
java.lang.OutOfMemoryError: Java heap space
at java.io.BufferedWriter.<init>(Unknown Source)
at java.io.BufferedWriter.<init>(Unknown Source)
at java.io.PrintWriter.<init>(Unknown Source)
at java.io.PrintWriter.<init>(Unknown Source)
at com.sun.org.apache.xerces.internal.util.DefaultErrorHandler.<init>(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.<init>(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.<init>(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.<init>(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.xs.InsulatedSchemaValidator.<init>(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaImpl.newXNIValidator(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.XercesSchema._newValidatorHandler(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.XercesSchema.newValidatorHandler(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.JAXPConfiguration.configurePipeline(Unknown Source)
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)
Many thanks for help,
Frank
Edited by: 863908 on Jun 6, 2011 8:09 AM
Edited by: 863908 on Jun 6, 2011 8:11 AM