I have taken a look at an example i found on the internet of xerces generating XML. The Transcode function seems to perform some encoding but the buffer it populates to is never released. According to the documentation you must release ti manually:
NOTE: The returned buffer is dynamically allocated and is the responsibility of the caller to delete it when not longer needed. You can call XMLString::release to release this returned buffer.
could doc->release be releasing this from memory?
XMLCh tempStr[100];
XMLString::transcode("Range", tempStr, 99);
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr, 0);
XMLString::transcode("root", tempStr, 99);
DOMDocument* doc = impl->createDocument(0, tempStr, 0);
DOMElement* root = doc->getDocumentElement();
XMLString::transcode("FirstElement", tempStr, 99);
DOMElement* e1 = doc->createElement(tempStr);
root->appendChild(e1);
XMLString::transcode("SecondElement", tempStr, 99);
DOMElement* e2 = doc->createElement(tempStr);
root->appendChild(e2);
doc->release();
Forgive me if I've misunderstood, but the version of transcode
you're using there doesn't actutally create or return any buffers, because it is modifying the one you've supplied (tempStr
) in place. Your example code will not leak memory.
The versions of transcode
which do return a buffer (eg. every other version except the ones in your example code block) use a MemoryManager
instance to perform the allocation. The documentation seems a little sparse here, but as far as I can tell the default XMLPlatformUtils::fgMemoryManager
makes no claims to clean up any memory it has allocated. You should therefore assume that you need to destroy that returned buffer yourself.