I used the xmldom in PLSQL for the first time last year for a customer to generate XML files with product data that get loaded into FREDHOPPER (search engine). There were close to 300K products that needed to be exported into these XML files and each XML file could only have 1000 products (limitation of FREDHOPPER not Oracle). So on average I would create 300 xml files, but I noticed that the PLSQL procedure started to slow down and take more PGA the longer it was running (it went as far as eating up close to 50+ percent of a 12GB system). So there was a memory leak, I checked my code but didn’t find a problem. The only thing I kept doing was opening and closing these DOMS in memory (PGA) so I started to suspect that. I remembered this little PLSQL procedure that would free unused memory that was still allocated to your heaps. It is called dbms_session.free_unused_user_memory. So now just before I call xmldom.newDocument, I call this dbms_session.free_unused_user_memory procedure and the performance improved, as the heap no longer grew and was steady around 10 percent of the memory. So I was able to improve the performance of the XMLDOM dramatically by releasing the unused memory.
Two weeks ago I got an phone call from a consultant who had a problem with XMLDOM on a windows machine (32 bit). The memory problems are even worse there and they he a small number of processes eat up all the available memory and error out with ora-4030. He asked if anything could be done about this and I remembered my little XMLDOM performance issue so I told him to call dbms_session.free_unused_user_memory every so often. And again the PLSQL program no longer runs into ora-4030 errors.
This is of course an Oracle problem, but at least we have an way to make XMLDOM perform better and use less memory.