Hi Enzo,
every parsed file is stored in a cache (unless you invoke adoptDocument to decide to own its lifetime by yourself); the cache is emptied when you call release() on the parser object. Your code doesn't release neither the parser or the error handler; try printing the memory allocated after you delete both objects.

Alberto

Enzo Arlati wrote:
I have xerces 2.7 on a redhat 7.3 and I have a memory leak of about 12 k when I run the parse() method of XercesDOMParser .
Belowe I copy the code involved.
Is there an error in the code or is this a bug ? /*****************************************************************************************/
int
util_xerces::BuildDomParser( XercesDOMParser ** domParser )
{
  int       iret;
( *domParser ) = new XercesDOMParser;
  ( *domParser )->setValidationScheme( XercesDOMParser::Val_Auto );
  ( *domParser )->setDoNamespaces( false );
  ( *domParser )->setDoSchema( false );
  ( *domParser )->setValidationSchemaFullChecking( false );
  ( *domParser )->setCreateEntityReferenceNodes( true );
iret = IRET_OK;
  return iret;
} // _________ void util_xerces::BuildDomParser( ) /*****************************************************************************************/
int
util_xerces::ParseXmlToDoc( string strXmlInp,  DOMDocument ** pDoc )
{
XercesDOMParser *pDomParserInput = 0;
  DOMTreeErrorReporter *errReporter     = 0;
  int       iret = IRET_ERROR;
  string Fun = "[ParseXmlToDoc] ";
*pDoc = 0; // --------------------------------------------------------------------------
  util_xerces::BuildDomParser( &pDomParserInput );
  errReporter = new DOMTreeErrorReporter(  );
  pDomParserInput->setErrorHandler( ( ErrorHandler * ) errReporter );
// -------------------------------------------------------------------------- // strXmlInp is a short string like this : *"<Messaggio TipoMsg=\"S\" />"* // --------------------------------------------------------------------------
  string    sfile;
sfile = ae_util::format_string( "/var/log/xml/tmp_inp_%d.xml", getpid( ) );
  std::ofstream out_file( sfile.c_str(  ) );
  out_file << strXmlInp;
  out_file.close(  );
// --------------------------------------------------------------------------
  try
  {
pDomParserInput->parse( sfile.c_str( ) ); * for( int ix = 0; ix < 5; ix++ )
    {
MYLOG( Fun + ae_util::format_string( " memoria allocata = %d ", ae_util::MemoriaProcesso( 0 ) ));
        pDomParserInput->parse( sfile.c_str(  ) );
    }*
unlink( sfile.c_str( ) );
  }
  catch( const XMLException & e )
  {
    MYERR( ae_util::
format_string( "[util_xerces::ParseXmlToDoc] XMLException parse ERROR %s [XML:%s]", S( e.getMessage( ) ).c_str( ), strXmlInp.c_str( ) ) );
  }
  catch( const DOMException & e )
  {
    const unsigned int maxChars = 2047;
    XMLCh     errText[maxChars + 1];
    char     *sMsg;
if( DOMImplementation::loadDOMExceptionMsg( e.code, errText, maxChars ) )
    {
      sMsg = XMLString::transcode( errText );
      MYERR( ae_util::
format_string( "[util_xerces::ParseXmlToDoc] DOMException parse ERROR %d -> %s ",
                            e.code, sMsg ) );
      XMLString::release( &sMsg );
    }
  }
  catch( ... )
  {
MYERR( ae_util::format_string( "[util_xerces::ParseXmlToDoc] parse ERROR [XML:%s]",
                                   strXmlInp.c_str(  ) ) );
  }
  ................
------------------------------------------------------------------------ the output is as follow: [][20090108_103115 PID:6682.6626] [TestMemoryLeak] START - memoria allocata = 4184 [][20090108_103115 PID:6682.6626] [TestMemoryLeak] InputMSG=[<Messaggio TipoMsg="S" />] *[][20090108_103115 PID:6682.6626] [ParseXmlToDoc] memoria allocata = 4220
[][20090108_103115 PID:6682.6626] [ParseXmlToDoc]  memoria allocata = 4232
[][20090108_103115 PID:6682.6626] [ParseXmlToDoc]  memoria allocata = 4244
[][20090108_103115 PID:6682.6626] [ParseXmlToDoc]  memoria allocata = 4256
[][20090108_103115 PID:6682.6626] [ParseXmlToDoc] memoria allocata = 4264*


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to