3
java.lang.OutOfMemoryError
at com.solvoterra.xmlengine.Element.<init>(Element.java:9)
at com.solvoterra.xmlengine.XML_Handler_Main.startElement(XML_Handler_Main.java:71)
at org.apache.harmony.xml.ExpatParser.startElement(ExpatParser.java:146)
at org.apache.harmony.xml.ExpatParser.append(Native Method)
at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:505)
at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:492)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:308)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:264)
at com.solvoterra.xmlengine.Project_Man.readXML_File(Project_Man.java:148)
at com.solvoterra.xmlengine.Project_Man.run(Project_Man.java:83)
at java.lang.Thread.run(Thread.java:1102)

I can see from this the error has occurred whilst running a new process which only contains the function to SAX Parse an XML file into memory (RAM) I don't know all the details as this information has been provided by an anonymous user on the market.

Before the function to Parse is called all buffers and memory is cleared of existing data.

Q: Is it possible that the user is trying to Parse a HUGE XML database into memory and the RAM allocated by his phone simply isn't enough to handle his database?

dev
1,3553 gold badges20 silver badges40 bronze badges
asked Dec 29, 2010 at 14:00
2
  • Maybe you should consider using the sqlite database and just browse with queries inside it instead of parsing XML ? Commented Dec 29, 2010 at 14:02
  • I'm writing an XML Editor you see. Commented Dec 29, 2010 at 14:03

2 Answers 2

1

Sax parsing method doesn't load things in memory itself (as opposed to DOM). Only your way of handling events generated by SAX can cause memory overload.

If you allow your users to chose freely an XML source, you have to either:

  • build a parsing algorithm which stores in BD or file the result of the parsing one element at a time
  • build a parsing algorithm which loads the first X elements of the XML source and if possible allows to fetch following elements when requested (paginate)
  • check the length of the XML source before parsing in order to display an error message to the user asking him to load a smaller source

Another reason for this OutOfMemoryError could be a memory leak in your application which is not related to your XML parser. For example, orientation changes, if not handled carefully, can easily cause memory leaks. If your application memory is saturated, the OutOfMemoryError can be triggered by ANY memory allocation, but this single memory allocation may not be responsible for the whole process memory saturation.

answered Dec 29, 2010 at 14:19
Sign up to request clarification or add additional context in comments.

3 Comments

Is it true that SAX reads an entire file in one go... if that's the case I did think of your second option however if the user is using lets say a 4mib XML file and the entire file has to be read every time the user wants to navigate to a new node that's going to lead to some pretty sluggish browsing. The easiest choice would of course be your 3rd Option, guess I need to run some tests with various file sizes etc
Is there a way of requesting more memory to be allocated to the application??
No, and the limit can be different on different devices.
0

Out of memory is easily possible (I mean if XML file placed in RAM). SAX Parser is a stream based parsing approach (in contrary to DOM Parser). So SAX itself can't consume a lot of memory. Best approach would be to save XML to external file/storage and the stream data from file directly to SAX Parser. This kind of approach exactly the way SAX parser should be used.

answered Dec 29, 2010 at 14:22

1 Comment

The XML file is indeed being passed into an array, so basically is just as hungry as a DOM parser. I think I'm going to run file size tests to determine just how many bytes are causing the OoME.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.