This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am using XSOMParser to parse large xsd files. When I am calling XSOMParser.parse(Filepath) method it is throwing out of memory error.
As I know XSOMParser internally uses SAX parser to parse document and SAX parser support event based mechanism and reads input line by line. So very less memory is required to parse large files. Correct me if wrong.
Please let me know if any one has worked on similar issue.
XSOMParser parser = new XSOMParser();
skumar kk wrote:As I know XSOMParser internally uses SAX parser to parse document and SAX parser support event based mechanism and reads input line by line. So very less memory is required to parse large files. Correct me if wrong.
That could be right (I'm not familiar with XSOM). Let's suppose it is. It still says nothing about whether XSOM takes the output of that SAX parser and builds some internal structure which can use up all available memory if it becomes large enough, so it isn't very helpful as an approach to your problem. Especially as there is no doubt that you are running out of memory.
But I wouldn't expect that an XML schema could be large enough to use up all available memory. Perhaps your schema is extremely large? Or perhaps there is something strange about it?
Perhaps there is some sort of recursion going on. I always suspect recursion when small jobs throw out of memory errors.
Joined: Apr 06, 2011
William Brogden wrote:Perhaps there is some sort of recursion going on. I always suspect recursion when small jobs throw out of memory errors.
Hi me getting error on XSOMParser.parse() method where we are not using any sort of recursion. I do not have information about how parse method was internally implemented.
Stack Trace :
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.xml.sax.helpers.XMLFilterImpl.endElement(Unknown Source)
at org.xml.sax.helpers.XMLFilterImpl.parse(Unknown Source)
Author and all-around good cowpoke
Joined: Mar 22, 2000
I could not find any JavaDocs for this class and method:
However, it sounds like a call to include another document - could this lead to a loop which just keeps including till it runs out of memory?
The xsom parser will certainly build its own object models in-memory (om of xsom stands for object model, does it not?). It is certainly not a sax parser. However, the AnnotationParser implements and use sax ContentHandlerm though. But what it, the AnnotationParser, builds and then returns through getResult() method can be a huge string or even use the resultant string to further parse it into dom tree (it gets that much of freedom there). Both stories can contribute to the stress on the memory usage.
I would suggest you first leave out the setAnnotationParser() part to see if it works fine in getting XSSchemaSet etc... and decide further action from there. (What is the sum of sizes of the xsd's on disk?) If that part loads well, then you've to look into your AnnotationParser implementation see what it actually does, if you really want to parse annotations as well. Since the implementation of the AnnotationParser is yours, I would not anticipate any difficulty in knowing what you want actually out of it and how big it would be of the object return through the getResult().