You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Chun-chieh Wang <sk...@seed.net.tw> on 2000/08/30 13:15:12 UTC
SAX parser memory management
Hello,
I have some problem in using Xerces-C parser on Red-Hat Linux.
I package the parser to a shared library to let other program to load
it.
The function is as follows:
-------------------------------------------------------------------------------------------------
int parseConfigFile(Data *data, char *filename){
try{
XMLPlatformUtils::Initialize();
}catch (const XMLException& toCatch){
return 1;
}
SAXParser *parser = new SAXParser();
parser->setValidationScheme(valScheme);
XmlHandlers *handler = new XmlHandlers( data, encodingName,
unRepFlags );
try{
parser->setDocumentHandler(&handler);
parser->setErrorHandler(&handler);
parser->parse(filename);
}catch (const XMLException& toCatch){
return -1;
}
delete handler;
delete parser;
return 0;
}
-------------------------------------------------------------------------------------------------
Every time I call this function, the program require about 4K memory,
but I don't know how to release this memory. My program have to
periodically parse the xml file, so that the memory will be exhausted
soon.
I have no idea about how to resolve this memory leak.
Should I use the parser this way?
I try to call the XMLPlatformUtils::Terminate () function,
but that makes my original program crash, that is, I can't reuse this
parser.
Please tell me how to fix that.
Thank you very much!
C. Wang
Re: SAX parser memory management
Posted by Dean Roddey <dr...@charmedquark.com>.
This :
XmlHandlers *handler = new XmlHandlers( data, encodingName,
unRepFlags );
try{
parser->setDocumentHandler(&handler);
parser->setErrorHandler(&handler);
is not correct. You already have a handler pointer, so you don't need to
take the address of it.
--------------------------
Dean Roddey
The CIDLib C++ Frameworks
Charmed Quark Software
droddey@charmedquark.com
http://www.charmedquark.com
"It takes two buttocks to make friction"
- African Proverb
----- Original Message -----
From: "Chun-chieh Wang" <sk...@seed.net.tw>
To: <xe...@xml.apache.org>
Sent: Wednesday, August 30, 2000 4:15 AM
Subject: SAX parser memory management
>
>
> Hello,
>
> I have some problem in using Xerces-C parser on Red-Hat Linux.
>
> I package the parser to a shared library to let other program to load
> it.
>
> The function is as follows:
>
> --------------------------------------------------------------------------
-----------------------
>
> int parseConfigFile(Data *data, char *filename){
>
> try{
> XMLPlatformUtils::Initialize();
> }catch (const XMLException& toCatch){
> return 1;
> }
> SAXParser *parser = new SAXParser();
> parser->setValidationScheme(valScheme);
>
> XmlHandlers *handler = new XmlHandlers( data, encodingName,
> unRepFlags );
> try{
> parser->setDocumentHandler(&handler);
> parser->setErrorHandler(&handler);
>
> parser->parse(filename);
>
> }catch (const XMLException& toCatch){
> return -1;
> }
> delete handler;
> delete parser;
>
> return 0;
> }
> --------------------------------------------------------------------------
-----------------------
>
>
>
> Every time I call this function, the program require about 4K memory,
> but I don't know how to release this memory. My program have to
> periodically parse the xml file, so that the memory will be exhausted
> soon.
>
> I have no idea about how to resolve this memory leak.
>
> Should I use the parser this way?
>
> I try to call the XMLPlatformUtils::Terminate () function,
> but that makes my original program crash, that is, I can't reuse this
> parser.
>
> Please tell me how to fix that.
>
>
>
> Thank you very much!
>
>
> C. Wang
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>