XERCESC 2.7 Memory Leak Problem

1.7k Views Asked by At

We are using XERCESC 2.7 unfortunately there is not too much about this topic on the web.

Question: What is the Workflow when parsing with Xerces? I will show the workflow i have and hopefully my memory leak will be spottet by somebody. Unfortunately i cannot install a memory debugger on the system due to restrictions.

Thanks OS

Constructor:

DOMBuilder * pDOMBuilder

pDOMBuilder =_pDOMImplementation->createDOMBuilder
(xercesc::DOMImplementationLS::MODE_SYNCHRONOUS, NULL);
        pDOMBuilder->setFeature(XMLUni::fgXercesUserAdoptsDOMDocument, true)
        pDOMBuilder->setFeature(xercesc::XMLUni::fgDOMNamespaces, true);
        pDOMBuilder->setFeature(xercesc::XMLUni::fgDOMValidation, true);
        pDOMBuilder->setFeature(xercesc::XMLUni::fgXercesSchema, true);
        pDOMBuilder->setFeature(xercesc::XMLUni::fgXercesSchemaFullChecking, true);
        pDOMBuilder->setFeature(xercesc::XMLUni::fgXercesValidationErrorAsFatal, true);
        pDOMBuilder->setFeature(xercesc::XMLUni::fgDOMWhitespaceInElementContent, false);
        pDOMBuilder->setFeature(xercesc::XMLUni::fgDOMDatatypeNormalization, true);
        m_pErrorHandler = new ErrorHandler();
        pDOMBuilder->setErrorHandler(m_pErrorHandler);
        pDOMBuilder->setEntityResolver(new EntityResolver(absolutePathToSchemas));

Destructor:

pDOMWriter->release();

Usage of the Object:

pDOMBuilder->resetDocumentPool();
pDOMBuilder->resetCachedGrammarPool(); 
m_ErrorHandler->reset();

xercesc::MemBufInputSource * pMemBufInputSource = new xercesc::MemBufInputSource((const XMLByte *)xmlStream, 
                                                                                         (unsigned int)strlen(xmlStream),
                                                                                         UnicodeString("xmlStream"));

xercesc::Wrapper4InputSource wrapper4InputSource(pMemBufInputSource);
xercesc::DOMDocument * resultDoc = m_DOMBuilder->parse(wrapper4InputSource);


resultDoc->release();
1

There are 1 best solutions below

2
On

Anything Xerces DOM object ptr acquired via a createXXX method should be released by calling its release method. You don't appear to be calling pDOMBuilder->release ().