Hi Adelino,
when you parse a document and retrieve it from the XercesDOMParser via the getDocument method, the DOM tree is still owned by the parser, and kept in an internal pool. When the parser is deleted, all the documents it parsed are deleted. So, the fact that you still see the leak even when you delete the xmlParser object is a hint that the leak is somewhere else, maybe in the code that navigates the DOM tree. Are you sure you are not using methods like XMLString::transcode()? They allocates memory that you must release. As for avoiding deleting the parser, you can also call xmlParser->resetDocumentPool() before the new call to parse()

Alberto

Il 10/06/14 00:16, Adelino Rocha ha scritto:
Hi,

I'm implementing a program which reads and parses an XML file when starts and then I would need to read same XML file again cyclicly to load the same file again to load any possible change.

Summarily what I'm doing is this based on this example <http://www.yolinux.com/TUTORIALS/XML-Xerces-C.html> (I skipped all error handling, etc):

        .....
        this->xmlParser = new XercesDOMParser();
        this->xmlErrHandler = (ErrorHandler*) new HandlerBase();
this->xmlParser->setErrorHandler(this->xmlErrHandler);
this->xmlParser->setValidationScheme(XercesDOMParser::Val_Auto);
        this->xmlParser->setDoNamespaces(true);
        this->xmlParser->setDoSchema(false);

*        this->xmlParser->resetDocument();*
*        this->xmlParser->parse(fileName);**
**        xmlDoc = xmlParser->getDocument();*

       .... read XML sections here


if I repeat the part in bold cyclicly I'm able to re-load the xml file successfully but I get a memory leak. Memory keeps increasing on each cycle.

    I had even tried to completely destroy the xml objects like this;

    this->xmlParser->reset();
    delete this->xmlParser;
    delete this->xmlErrHandler;
    this->xmlParser = NULL;
    this->xmlErrHandler = NULL;

    and intialize them again but still have a leak

So my question is how can I cyclicly read an xml file without having a memory increase on every read and without having to almost destroy all objects and recreate tham back again ?

     Thanks,

        Adelino.








Reply via email to