The memory is owned by the DOMDocument, which is owned by the parser
(as you used getDocument instead of adoptDocument to obtain it).
Can you check if the memory is still allocated after the "delete
parser;" statement?
Alberto
On 10/1/2010 11:35 AM, Peter Gerell wrote:
Hi
I have a problem with memory leaks in my application.
The memory is allocated from within DOMTextImpl::getWholeText() using
GetDOMNodeMemoryManager->allocate().
As far as I can tell this memory should be owned by the implementation and
released automatically.
Is this a bug or am I doing something wrong?
I get one leaked object when running the following example.
Best Regards Peter
My input looks like this
<?xml version="1.0" encoding='utf-8' ?>
<root>Foo</root>
My code looks like this:
int main() {
std::string msg;
XercesDOMParser* parser = 0;
DOMImplementation* impl = 0;
try {
XMLPlatformUtils::Initialize();
XMLCh* t = XMLString::transcode("XML 1.0 Traversal 2.0");
impl = DOMImplementationRegistry::getDOMImplementation(t);
XMLString::release(&t);
parser = new XercesDOMParser();
parser->setValidationScheme(XercesDOMParser::Val_Never);
parser->setDoNamespaces(false);
parser->setDoSchema(false);
parser->setLoadExternalDTD(false);
parser->parse("a.xml");
DOMDocument* doc = parser->getDocument();
DOMElement* root = doc->getDocumentElement();
char *c = XMLString::transcode(root->getTagName());
std::cout<< c<< std::endl;
XMLString::release(&c);
DOMNodeList* childList = root->getChildNodes();
const XMLSize_t childCount = childList->getLength();
assert(childCount==1);
DOMNode* node = childList->item(0);
assert(node);
assert(node->getNodeType() == DOMNode::TEXT_NODE);
const XMLCh* tempStr = static_cast<DOMText*>(node)->getWholeText(); //
This object is leaked
c = XMLString::transcode(tempStr);
std::cout<< "Text = "<< c<< std::endl;
XMLString::release(&c);
} catch (const XMLException& xexp) {
char * message = XMLString::transcode(xexp.getMessage());
msg = std::string(message);
XMLString::release(&message);
} catch (const DOMException& dexp) {
char * message = XMLString::transcode(dexp.getMessage());
msg = std::string(message);
XMLString::release(&message);
}
std::cout<< msg;
delete parser;
XMLPlatformUtils::Terminate();
return 0;
}
.