Thank you.
I am now releasing the buffer myself and the memory leak is gone.
To be able to call XMLString::release, I had to cast away the constness of the 
pointer.

Peter
 

-----Original Message-----
From: Alberto Massari [mailto:[email protected]] 
Sent: den 1 oktober 2010 18:29
To: [email protected]
Subject: Re: Memory leak in DOMText::getWholeText?

  It turns out that getWholeText doesn't use the pooled memory manager 
of DOMDocument, but simply the memory manager. So you have to call 
XMLString::release on the returned pointer.

At this point the doubt is: should we fix the documentation, or the 
code? Because, if we fix the code, we are going to break existing code 
that does the right thing and releases the pointer.... Boris, David, 
Michael (and others), what do you think?

Alberto

On 10/1/2010 1:38 PM, Peter Gerell wrote:
> As far as I can tell it is still allocated.
> I am using vld (Visual Leak Detector) which in my experience usually don't 
> report any false leaks.
> If I comment out the deletion of the parser I get 154 memory leaks.
> Also commenting out XMLPlatformUtils::Terminate() gives 3410 leaks.
>
> Peter
>
>
> -----Original Message-----
> From: Alberto Massari [mailto:[email protected]]
> Sent: den 1 oktober 2010 13:17
> To: [email protected]
> Subject: Re: Memory leak in DOMText::getWholeText?
>
>    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;
>> }
>>
>> .
>>
>
>
> .
>



Reply via email to