Hi there,

I have tried to compile multiple Stylesheets, store the pointers to the compiled stylesheets within a stl list, do some transformations, and destroy the stylesheets one after another. After each stylesheet compilation and after each stylesheet destruction, I glimpsed into /proc/self/statm, the memory usage of the current process on linux machines. I was wondering why the memory usage stays at a high level even after the destruction of the compiled stylesheets and the termination of the library.

Is there anywhere a memory leak with the usage of multiple compiled stylesheets? Or am I wrong with my interpretation of the memory usage of the process? Does anybody see the same results?

I have attached the source of the test, a modified version of the compiled stylesheet example. It does only run on linux machines. You have to put the foo*-files from the compiled stylesheet sample within the same directory. I used this on RedHat WS3.0 with "gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-24)", Xalan-C 1.7 (slightly modifed) and Xerces-C 2.4 (slightly modifed). My results are:
Start
821 821 763 4 813 4 58
compiled Stylesheet #0
1140 1140 1052 4 1102 34 88
compiled Stylesheet #1
1150 1150 1052 4 1102 44 98
compiled Stylesheet #2
1157 1157 1052 4 1102 51 105
compiled Stylesheet #3
1166 1166 1052 4 1102 60 114
compiled Stylesheet #4
1173 1173 1052 4 1102 67 121
compiled Stylesheet #5
1180 1180 1052 4 1102 74 128
compiled Stylesheet #6
1186 1186 1052 4 1102 80 134
compiled Stylesheet #7
1192 1192 1052 4 1102 86 140
compiled Stylesheet #8
1199 1199 1052 4 1102 93 147
compiled Stylesheet #9
1206 1206 1052 4 1102 100 154
...
destroying Stylesheet
1262 1262 1100 4 1150 108 162
destroying Stylesheet
1262 1262 1100 4 1150 108 162
destroying Stylesheet
1262 1262 1100 4 1150 108 162
destroying Stylesheet
1262 1262 1100 4 1150 108 162
destroying Stylesheet
1262 1262 1100 4 1150 108 162
destroying Stylesheet
1262 1262 1100 4 1150 108 162
destroying Stylesheet
1262 1262 1100 4 1150 108 162
destroying Stylesheet
1262 1262 1100 4 1150 108 162
destroying Stylesheet
1262 1262 1100 4 1150 108 162
destroying Stylesheet
1262 1262 1100 4 1150 108 162
Xalan terminated
1264 1264 1102 4 1152 108 162
Xerces terminated
1266 1266 1104 4 1154 108 162
End


Regards,

HolgeR
--
holger floerke                      d  o  c  t  r  o  n  i  c
email [EMAIL PROTECTED]          information publishing + retrieval
phone +49 2222 9292 90              http://www.doctronic.de

#include <xalanc/Include/PlatformDefinitions.hpp>

#include <cassert>

#if defined(XALAN_CLASSIC_IOSTREAMS)
#include <fstream.h>
#include <iostream.h>
#include <strstream.h>
#else
#include <fstream>
#include <iostream>
#include <strstream>
#endif

#include <xercesc/util/PlatformUtils.hpp>

#include <xalanc/XalanTransformer/XalanTransformer.hpp>

#include <stdio.h>
#include <list>
using namespace std;


void printMem()
{
  FILE* fIn = fopen("/proc/self/statm","r");
  char buf[256];
  fgets(buf,255,fIn);
  fclose(fIn);
  cout << buf;
}


int
main(
      int    argc,
      char*  /* argv */[])
{
  cout << "Start" << endl;
  printMem();

  XALAN_USING_STD(cerr)
  XALAN_USING_STD(endl)
  XALAN_USING_STD(ostrstream)

  int  theResult = 0;

  if (argc != 1)
  {
    cerr << "Usage: CompileStylesheet"
       << endl
       << endl;
  }
  else
  {
    XALAN_USING_XERCES(XMLPlatformUtils)
    XALAN_USING_XERCES(XMLException)

    XALAN_USING_XALAN(XalanTransformer)
    XALAN_USING_XALAN(XalanCompiledStylesheet)

    // Call the static initializer for Xerces.
    try
    {
       XMLPlatformUtils::Initialize();
    }

    catch (const XMLException& toCatch)
    {
       cerr << "Error during Xerces initialization! "<< endl;
        
       theResult = -1;
    }

    if ( theResult == 0)
    {
      
      // Initialize Xalan.
      XalanTransformer::initialize();
      
      {
        // Create a XalanTransformer.
        XalanTransformer theXalanTransformer;
        
        // Our input files...The assumption is that the executable will be run
        // from same directory as the input files.
        const char*    theXSLFileName = "foo.xsl";
        
        // Compile the stylesheet.
        list<const XalanCompiledStylesheet*> oStyleList;
        const XalanCompiledStylesheet*  theCompiledStylesheet = 0;

        for (int i = 0; i < 10; i++)
        {
          const XalanCompiledStylesheet*  theCompiledStylesheet = 0;
          theResult =  theXalanTransformer.compileStylesheet(theXSLFileName, 
theCompiledStylesheet);
                
          if (theResult == 0)
          {
            assert(theCompiledStylesheet != 0);

            cout << "compiled Stylesheet #" << i << endl;
            printMem();
            oStyleList.push_back(theCompiledStylesheet);
          }
          else
          {
            cerr << "CompileStylesheet Error: " << 
theXalanTransformer.getLastError()
                 << endl
                 << endl;
          }
        }

        for (list<const XalanCompiledStylesheet*>::const_iterator oIt = 
oStyleList.begin();
             oIt != oStyleList.end();
             oIt++)
        {
          cout << "using new Stylesheet..." << endl;

          theCompiledStylesheet = *oIt;
          
          for (unsigned int i = 0; i < 10; ++i)
          {    
            cout << "  transform #" << i << endl;

            // Buffers passed in to ostrstream.
            char  inBuffer[10];
            char  outBuffer[10];  
            
            // Generate the input and output file names.
            ostrstream  theFormatterIn(inBuffer, sizeof(inBuffer));
            ostrstream  theFormatterOut(outBuffer, sizeof(outBuffer));
            
            theFormatterIn << "foo" << i + 1 << ".xml" << '\0';
            theFormatterOut << "foo" << i + 1 << ".out" << '\0';
            
            // Do the transform.
            theResult = theXalanTransformer.transform(
              inBuffer,
              theCompiledStylesheet,
              outBuffer);
          }
          
        }

        for (list<const XalanCompiledStylesheet*>::const_iterator oIt = 
oStyleList.begin();
             oIt != oStyleList.end();
             oIt++)
        {
          cout << "destroying Stylesheet" << endl;
          theCompiledStylesheet = *oIt;
          theXalanTransformer.destroyStylesheet(theCompiledStylesheet);
          printMem();
        }
        oStyleList.clear();

      }
    }

    // Terminate Xalan...
    XalanTransformer::terminate();

    cout << "Xalan terminated" << endl;
    printMem();

    // Terminate Xerces...
    XMLPlatformUtils::Terminate();

    cout << "Xerces terminated" << endl;
    printMem();

    // Clean up the ICU, if it's integrated.
    XalanTransformer::ICUCleanUp();
  }

  cout << "End" << endl;
  printMem();

  return theResult;
}

Reply via email to