If this was my problem I would certainly consider writing the document to a temporary file.
Furthermore, I'm sure StringBuilder delete is not going to immediately free up memory, just changes internal pointers.
If you use the java.io.File.createTempFile() method it takes care of finding a location, and the deleteOnExit() should do the cleanup for you.
But, I cannot do that as I start parsing the document, I'll allocate more and more memory for the java object in the course of parsing and I'll reach Heap upper limit causing OutOfMemory. Because I am having the entire XML document also in memory.
If you process the XML-based document with a SAX implementation, you will never have the "entire XML document in memory."
This is the first time you mentioned concern about JAVA only implementation.
Lets back up a bit.
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|