You should _not_ call XalanTransformer::destroyParsedSource() with an
instance you create yourself on the stack.  The documentation is explicit
about this.

Also, you don't need to do this:

   delete [] oOStream.str();

since you haven't called ostrstream::str().

I don't know if there's a memory leak issue.  We haven't found one, but
I'll try to do some testing with your code.

Dave



                                                                                       
                                       
                      Holger Floerke                                                   
                                       
                      <floerke@doctron         To:      [EMAIL PROTECTED]       
                                       
                      ic.de>                   cc:      (bcc: David N 
Bertoni/Cambridge/IBM)                                  
                                               Subject: Xalan-C++ - 
XercesDOMWrapperParsedSource consuming memory             
                      03/15/2002 01:37                                                 
                                       
                      AM                                                               
                                       
                      Please respond                                                   
                                       
                      to xalan-dev                                                     
                                       
                                                                                       
                                       
                                                                                       
                                       



Hi there,

   I try to use the Xalan-C++ TransformerAPI to transform a Xerces-DOM. As
mentioned in the "usage patterns" I have to use
XercesDOMWrapperParsedSource to do this. Fine, works.

   The problem is, I see the memory growing in my task-manager (Xalan-C++
1.3, Win32 on W2KSP2). You can reproduce this with a simple code I have
added to this Mail.

   My question is: Am I wrong in using XercesDOMWrapperParsedSource, or is
this a bug (then I will post it to the bug database)?


tia

HolgeR


#include <Include/PlatformDefinitions.hpp>
#include <util/PlatformUtils.hpp>
#include <parsers/DOMParser.hpp>


#include <XalanTransformer/XalanTransformer.hpp>

#include <XalanTransformer/XercesDOMWrapperParsedSource.hpp>
#include <XercesParserLiaison/XercesParserLiaison.hpp>
#include <XercesParserLiaison/XercesDOMSupport.hpp>

#include <stdio.h>

#include <strstream>
using namespace std;

void main()
{
   XMLPlatformUtils::Initialize();
   XalanTransformer::initialize();

   XercesDOMSupport oDOMSupport;
   XercesParserLiaison oParserLiaison(oDOMSupport);


   // using Xerces-DOM as Source
   DOM_DOMImplementation oImplementation;

   DOM_Document oDocument = oImplementation.createDocument(
                "http://foo";,
                "foo:fritz",
                DOM_DocumentType());

   // transforming to death...
   XalanTransformer oTransformer;

   for (;;)
   {
     // using ostrstream as Result
     ostrstream oOStream;

     XSLTResultTarget oResult(oOStream);

     // using istrstream as Stylesheet
     char* pcStylesheet = "<?xml version=\"1.0\"?>\
   <xsl:stylesheet version=\"1.0\" \
   xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\";> \
   <xsl:template match=\"fritz\"><A>result</A></xsl:template> \
   </xsl:stylesheet>";

     istrstream oIStream(pcStylesheet,strlen(pcStylesheet));

     XSLTInputSource oStylesheet(&oIStream);


     // consuming memory ???
     const XercesDOMWrapperParsedSource
         oSource (oDocument,
                  oParserLiaison,
                  oDOMSupport,
                  XalanDOMString("FormatterInputSource"));

     // ok
     /*char* pcSource = "<?xml version=\"1.0\"?><foo:fritz
xmlns:foo=\"http://foo\"/>";
     istrstream oIStreamSource(pcSource,strlen(pcSource));
     XSLTInputSource oSource(&oIStreamSource);*/

     int nResult =
       oTransformer.transform(oSource,
                              oStylesheet,
                              oResult);


     // Am I right?
     oTransformer.destroyParsedSource(&oSource);

     if (nResult != 0)
     {
       printf("XSLTFormatter: Fehler bei der Transformation %i ('%s')",
              nResult,
              oTransformer.getLastError());
       break;
     }
     else
     {
       printf("*");
     };



     delete [] oOStream.str();
   };
}






Reply via email to