Hi there : )
I think I'm going nuts : (
Thanks to Alberto, I've got a code which is approximatively good. As told in
a previous post, I implemented a functional layer over the xerces library so
that we can use it in our software at work.
In order to control as much as possible the memory leaks, I created a
singleton which can (and only it can) create DOMDocument and
XercesDOMParser. It is reponsible too for the releasing of the objets.
So for the parser, I've got a release method :
void XMLFactory::releaseParser(ParserXML* p_poParser)
{
#ifdef AFF
cout << "XMLFactory::releaseParser()" << endl;
#endif
// suppression en se basant sur les adresses des objets
for (int i=0; i<m_oListeParserXML.entries(); i++)
{
ParserXML* ptr = NULL;
ptr = m_oListeParserXML.at(i);
if (ptr == p_poParser)
m_oListeParserXML.removeAt(i);
}
// on delete l'objet (on test avant s'il n'est pas NULL avec le
ThrowIfNullWithMsg)
DeleteIfObject(p_poParser);
}
In the destructor of the Parser, I've got this :
ParserXML::~ParserXML()
{
#ifdef AFF
cout << "Destructeur de ParserXML" << endl;
#endif
if (m_poDocument != NULL)
{
m_poDocument->release();
}
m_poDOMParser->reset();
DeleteIfObject(m_poDOMParser);
DeleteIfObject(m_poErrorHandler);
DeleteIfObject(m_poDOMDocument);
DeleteIfObject(m_poElementXML);
}
Some strange things happen, especially when I compare my code to the DOM
Programming Guide Chapter "Constructing a XercesDOMParser"
(http://xerces.apache.org/xerces-c/program-dom-3.html). It seems that, to
delete a parser and its ressources, one only have to delete the parser.
If I do that, I get a core Dump while deleting the DOMDocument.
So I added a m_poDOMParser->resetDocumentPool(), but it had the same effect.
Then I tried with m_poDOMParser->reset() and it did work! Well, not that
much. Sometimes it does, sometimes it doesn't. I still get a core Dump
sometimes, always when deleting the parser...
Just for the record, here is the parsing method :
ElementXML* ParserXML::parse(const char* p_pcBuffer)
{
#ifdef AFF
cout << "ParserXML::parse()" << endl;
#endif
// Si aucun buffer n'est passé, on renvoie NULL
if (p_pcBuffer == NULL)
{
return NULL;
}
// si le parser n'a pas libéré les ressources du précédent parse
if (m_bDocumentParsed)
{
if (m_poDocument != NULL)
{
m_poDocument->release();
}
m_poDOMParser->reset();
m_bDocumentParsed = false;
}
char* l_pcMessage;
// on crée un objet pour le parsing
MemBufInputSource l_oInputSource((const XMLByte*)p_pcBuffer,
strlen(p_pcBuffer),
(const XMLCh*) "ParserXML");
try
{
// on parse
m_poDOMParser->parse(l_oInputSource);
// on récupère le DOMDocument parsé
m_poDocument = m_poDOMParser->getDocument();
// on libère la mémoire si besoin
DeleteIfObject(m_poElementXML);
//on crée un nouveau ElementXML avec les données du DOMDocument
m_poElementXML = new ElementXML(m_poDocument->getDocumentElement());
// on indique que le Document a été correctement parsé
m_bDocumentParsed = true;
// on retourne l'ElementXML ainsi créé
return m_poElementXML;
}
catch(XMLException& XMLEx)
{
l_pcMessage = XMLString::transcode(XMLEx.getMessage());
ExceptMessage ex("T00500", "XML Exception", l_pcMessage);
XMLString::release(&l_pcMessage);
ex.doThrow();
}
catch(DOMException& DOMEx)
{
l_pcMessage = XMLString::transcode(DOMEx.msg);
ExceptMessage ex("T00501", "XML Exception", l_pcMessage);
XMLString::release(&l_pcMessage);
ex.doThrow();
}
catch(SAXParseException& SaxParseEx)
{
l_pcMessage = XMLString::transcode(SaxParseEx.getMessage());
ExceptMessage ex("T00502", "SAXParse Exception", l_pcMessage);
XMLString::release(&l_pcMessage);
ex.doThrow();
}
catch(SAXException& SaxEx)
{
l_pcMessage = XMLString::transcode(SaxEx.getMessage());
ExceptMessage ex("T00502", "SAX Exception", l_pcMessage);
XMLString::release(&l_pcMessage);
ex.doThrow();
}
catch(...)
{
ExceptMessage ex("T00450", " ", "Erreur inconnue");
ex.doThrow();
}
}
You just can't imagine how happy will I be when I won't have to code into
this libraby :D
Anyway, as always, if you find something weird, or even the tinniest clue,
please, post here.
Thanks a lot.
--
View this message in context:
http://www.nabble.com/Core-Dump-while-releasing-Parser-ressources...-tp23560721p23560721.html
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]