>From the Xerces API documentation:

  XMLCh* XMLString::transcode ( const char *const toTranscode ) [static]

  Transcodes a string to native code-page.

  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.

So every time you call transcode(), you should be saving the returned
pointer in order to release its memory. The following will leak the
memory allocated by transcode():

  someCall(XMLString::transcode("some string"));

If the examples really use this idiom, something is wrong, either in the
documentation (which I believe to be correct) or in the samples.

________________________________

        From: Monica Lau [mailto:[EMAIL PROTECTED] 
        Sent: Thursday, April 08, 2004 11:43 PM
        To: [EMAIL PROTECTED]
        Subject: Re: DOMWriter Questions
        
        
        Hi all,
         
        Thanks for all your responses.  In the following code snippet
(taken from DOMCreation and from DOMPrint), I just want to make sure
that I've deleted all the memory approriately.  Does the
"getDOMImplementation()" function allocate memory on the heap?  (I've
looked at the online documentation, but couldn't find much about this.)

         
        Thanks again for your time and help.
         
        Regards,
        Monica
         
         
        DOMImplementation *impl =
        
DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Co
re"));
        
        DOMDocument *mydoc =
        impl->createDocument(0,XMLString::transcode("company"),0);
        DOMElement *rootElem = mydoc->getDocumentElement();
        DOMElement *prodElem =
        mydoc->createElement(XMLString::transcode("product"));
        rootElem->appendChild(prodElem);
        DOMText *prodDataVal =
        mydoc->createTextNode(XMLString::transcode("Xerces-C"));
           prodElem->appendChild(prodDataVal);
        
        DOMWriter *writer = impl->createDOMWriter();
        cout <<
        XMLString::transcode(writer->writeToString(*mydoc)) <<
        endl;
        
        // Delete Memory
        writer->release();
        mydoc->release();
        delete impl;

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to