Frédéric Bauchet wrote: > > When using DOMWriter example with sun JDK1.1.8 on Windows NT 4, > I get the following error message with an XML file of 1.5 Mega bytes. > > java.lang.OutOfMemoryError:
DOM is a memory intensive data structure. You must increase your allowable heap size if you want to be able to read in a large document. > With JDK1.2.2 that's works fine but it tooks 35 Mb of memory to parse Java 2 has a larger default heap size (32M) than Java 1.1 (16M). > Does anybody know why the "print" method tooks so much memory ? We have a "deferred" DOM implementation that only creates those DOM nodes that you actually traverse. This allows the parser to parse and return a document much quicker than if it had to create all of the nodes up front. As with all programming problems, it gains a speed increase at the expense of more memory. Because the deferred implementation is the default, it takes more memory when you traverse the tree. You can turn off the deferred mode, but the DOM tree will still take a lot of memory because of all of those node objects. The following code will turn off the feature: DOMParser parser; parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false); The lesson to be learned is only use the DOM if it's appropriate to your task. If you can get away with using SAX, then use that instead. -- Andy Clark * IBM, JTC - Silicon Valley * [EMAIL PROTECTED]