1

I'm currently struggling with rising memory usage in Xerces-C.

I was able to simplify the code to this point:

xercesc_3_2::XMLPlatformUtils::Initialize();

xercesc_3_2::DOMImplementation* impl = xercesc_3_2::DOMImplementationRegistry::getDOMImplementation((const XMLCh*)L"LS");
xercesc_3_2::DOMDocument* doc = impl->createDocument();

while (true)
{
    xercesc_3_2::DOMElement* el = doc->createElement((const XMLCh*)L"root");
    el->release();
}

When I execute this code, the memory usage will rise up to 4 GB in ~30 seconds.

  • Do I have to call anything else than release() on the DOMElement in order to free the memory?
  • Is there any way to truly free the memory used by a DOMElement without releasing the DOMDocument

Some remarks to my questions:

  • I can't destroy the DOMDocument. (Unfortunately I have to keep it around with a lot of DOMElements being created and released)
  • I know this is technically not a memory leak since the memory will free when i release the DOMDocument, but is this a known issue?
  • I've tested the xerces-c versions 3.1.1, 3.1.4. 3.2.2. The problem exists in all those versions.
ParkerHalo
  • 4,341
  • 9
  • 29
  • 51
  • Why are you deleting elements you've created? What stops you from doing the "do I actually want to create this element" logic before you create the element? – Sneftel Oct 01 '19 at 14:19
  • But if you've actually added the elements to the document but the document isn't complete, you wouldn't be able to free those elements in any case. – Sneftel Oct 01 '19 at 14:30
  • @Sneftel I think we're moving off-topic here. – ParkerHalo Oct 02 '19 at 08:46
  • Well, that depends on whether confirming that there's a bug in Xerces (sounds like there is!) will be enough to solve your problem. I suspect that it won't be. – Sneftel Oct 02 '19 at 08:48
  • @Sneftel I'll do my best to explain our situation: Our users are creating XML trees with our tool. at some point they can 'save' the trees by importing them into a new `DOMDocument` and wiriting the XML to a file. After importing the trees into the new Documents (xerces actually clones the old trees) we want to delete (release) the old trees, which kind of leaks memory. – ParkerHalo Oct 02 '19 at 08:53
  • Ah. It sounds like you're using Xerxes as a generalized DOM rather than just an XML reading/writing tool. That's not the worst idea, but as you've seen, it's somewhat swimming against the current as far as Xerxes is concerned. Personally I'd suggest a custom, domain-specific data model/representation and a more streamy serialization to XML. DOM-based libraries make more sense for reading than writing anyway. – Sneftel Oct 02 '19 at 18:48

0 Answers0