Hi Dave,
Thank you for your reply.
You are correct that I need to release the XMLCh* that is returned from
transcode. But this is not the leak.
The reason I didn't show the release in the code snippet I posted, is
because in reality I have a class that does this transcoding, which does the
release in the destructor. I didn't want to post it because it is only extra
code to look at.
The leak is definitely in the write to string. If you write a simple .exe
and call this function multiple times, you will see your memory usage
increase dramatically. Take out the call to writeToString(), and it doesn't
increase at all.
This is quite a big issue for me, as I have an application that is creating
messages in XML and sending them between processes, so this gets called
quite a lot.
Thanks,
Brendan
David Bertoni wrote:
>
> On 2/26/2010 9:00 AM, brendanr wrote:
>>
>> Hi,
>>
>> I am using xerces C++ 3.1.0.
>> I have the following code that is causing a memory leak. I have looked
>> through previous posts regarding xmlToString, and the seem to say that
>> calling 'release()' on the Serializer fixes the memory leak.
>>
>> Can anyone point out what I am doing incorrectly here? when I remove the
>> line of code containing writeToString, the leak disappears (but obviously
>> I
>> am not getting my string!!)
> Are you sure that's the only line of code you removed? What about the
> call to XMLString::transcode()?
>
>>
>> //pDoc is a class member, and converToString is a class method
>> std::string convertToString(void)
>> {
>> // Factory method for getting a DOMImplementation object.
>> // The DOM implementation retains ownership of the returned object.
>> // Application code should NOT delete it.
>> DOMImplementation* impl = DOMImplementation::getImplementation();
>>
>> // get a serializer, an instance of DOMLSSerializer
>> DOMLSSerializer *theSerializer =
>> ((DOMImplementationLS*)impl)->createLSSerializer();
>>
>> XMLCh* toTranscode= theSerializer->writeToString(pDoc);
>> std::string transcodedStr =
>> std::string(XMLString::transcode(toTranscode));
> The leak is here, in the call to XMLString::transcode(), because you
> need to call XMLString::release() on the pointer that's returned. Please
> read the documentation for XMLString::transcode() carefully.
>
> char* transcodedData = XMLString::transcode();
> const std::string transcodedStr(transcodedStr);
> XMLString::release(&transcodedData);
>
> ...
>
> Dave
>
>
--
View this message in context:
http://old.nabble.com/writeToString-memory-Leak-tp27720774p27722998.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.