Bonjour à tous,
pour mon taf, un parserXML a été implémenté avec Xerces 2.4, mais nous avons toujours eu une fuite mémoire (sur serveur AIX5.1).
J'ai donc repris la dernière version de xerces (3.0.1), recompilé sur AIX 5.1 et fais ce petit bout de code tout con. Il crée des fichiers XML en boucle avec dans les fichiers XML, une répétition de balises.
J'ai récupérer une partie du code du site de xerces (Dom programming guide --> http://xerces.apache.org/xerces-c/program-dom-3.htm)
Voici le code :
Code :
void bJTOTest::Traiter()
{
XMLPlatformUtils::Initialize();
for (int i = 0; i < 500; i++)
creerFichierXML(i);
}
void bJTOTest::creerFichierXML(int p_iIndex)
{
cout << "Traitement du fichier " << p_iIndex << endl;
char tc_pid[10];
cout << "Conso MEMOIRE AV DEMANDE" << endl;
sprintf(tc_pid,"ps v %d", getpid());
system(tc_pid);
char l_tcFilePath[50+1];
memset(l_tcFilePath, '\0', sizeof(l_tcFilePath));
sprintf(l_tcFilePath, "XML/Test%d.xml", p_iIndex);
// Doc XML
DOMDocument* myDoc = NULL;
XMLCh tempStr[100];
//XMLString::transcode("LS", tempStr, 99);
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));
// on crée le doc
myDoc = impl->createDocument();
cout << " Création du noeud ID" << endl;
DOMElement* firstChild;
firstChild = myDoc->createElement(XMLString::transcode("array-list"));
cout << " Ajout du noeud root dans le doc" << endl;
myDoc->appendChild(firstChild);
// création des Noeuds
// Premier Node : Individu
for (int i=0; i<30; i++)
{
char* l_pcMessage = NULL;
try
{
cout << "Insertion d'une nouvelle entite ID" << endl;
cout << " Création du noeud ID" << endl;
DOMElement* firstChild;
firstChild = myDoc->createElement(XMLString::transcode("Individu"));
cout << " Création du NOM" << endl;
DOMElement* secondChild;
secondChild = myDoc->createElement(XMLString::transcode("Nom"));
DOMText* secondTextNode;
secondTextNode = myDoc->createTextNode(XMLString::transcode("WAZA"));
secondChild->appendChild(secondTextNode);
firstChild->appendChild(secondChild);
cout << " Création du PRENOM" << endl;
DOMElement* thirdChild;
thirdChild = myDoc->createElement(XMLString::transcode("Prenom"));
DOMText* thirdTextNode;
thirdTextNode = myDoc->createTextNode(XMLString::transcode("WAZA"));
thirdChild->appendChild(thirdTextNode);
firstChild->appendChild(thirdChild);
cout << " Création du SEXE" << endl;
DOMElement* fourthChild;
fourthChild = myDoc->createElement(XMLString::transcode("Sexe"));
DOMText* fourthTextNode;
fourthTextNode = myDoc->createTextNode(XMLString::transcode("HOMME"));
fourthChild->appendChild(fourthTextNode);
firstChild->appendChild(fourthChild);
cout << " Ajout du noeud dans le doc" << endl;
myDoc->getDocumentElement()->appendChild(firstChild);
}
catch(XMLException& XMLEx)
{
l_pcMessage = XMLString::transcode(XMLEx.getMessage());
cout << "XMLException <" << l_pcMessage << endl;
XMLString::release(&l_pcMessage);
}
catch(DOMException& DOMEx)
{
l_pcMessage = XMLString::transcode(DOMEx.msg);
cout << "DOMException <" << l_pcMessage << "> code <" << DOMEx.code << ">" << endl;
XMLString::release(&l_pcMessage);
}
catch(SAXException& SaxEx)
{
l_pcMessage = XMLString::transcode(SaxEx.getMessage());
cout << "SAXException <" << l_pcMessage << endl;
XMLString::release(&l_pcMessage);
}
catch(...)
{
cout << "OtherException <" << endl;
}
}
cout << "Serialisation..." << endl;
serializeDOM(myDoc, l_tcFilePath);
cout << "Conso MEMOIRE APS DEMANDE" << endl;
sprintf(tc_pid,"ps v %d", getpid());
system(tc_pid);
// on a fini avec le domcument, on libère la mémoire
release(myDoc);
}
void bJTOTest::release(DOMDocument* myDoc)
{
cout << "release" << endl;
myDoc->release();
}
int bJTOTest::serializeDOM(DOMNode* node, char* path)
{
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMLSSerializer* theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMLSOutput* theOutput = ((DOMImplementationLS*)impl)->createLSOutput();
try
{
theSerializer->writeToURI(node, XMLString::transcode(path));
}
catch (const XMLException& toCatch)
{
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n"
<< message << "\n";
XMLString::release(&message);
return -1;
}
catch (const DOMException& toCatch)
{
char* message = XMLString::transcode(toCatch.msg);
cout << "Exception message is: \n"
<< message << "\n";
XMLString::release(&message);
return -1;
}
catch (...)
{
cout << "Unexpected Exception \n" ;
return -1;
}
theOutput->release();
theSerializer->release();
return 0;
}
Je release bien le serializer et le DOMLSOutput ainsi que le DOMDocument. Il est en effet indiqué dans la doc que, je cite :
Citation:
When a DOMDocument is released, all its associated children AND any objects it owned (e.g. DOMRange, DOMTreeWalker, DOMNodeIterator or any orphaned nodes) will also be released.
ce que je comprend par : releasez le DOMDocument et tous les noeuds fils seront à leur tour releasés non?
Quoiqu'il en soit, j'ai toujours une fuite mémoire puisque la conso du serveur (visualisée grace au 'ps') ne descend jamais..
Si vous avez des idées, je suis complètement coincé là...
Merci : )