Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutOfMemoryError

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?

like image 200
Jay Dee Avatar asked Jun 05 '26 17:06

Jay Dee


1 Answers

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.

like image 100
Kevin Gaudin Avatar answered Jun 07 '26 07:06

Kevin Gaudin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!