[Xerces 3.0.1] Fuite de mémoire
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
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 : )