Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xml parsing memory leak

Reply
Thread Tools

xml parsing memory leak

 
 
keepyourstupidspam
Guest
Posts: n/a
 
      11-23-2005
In the code below I am trying to read text in an xml file, this works
fine but creates a memory leak of about 400K each time. This code is
called from a loop in a windows service so I can not just terminate the
app to cleanup, any ideas how to free this memory.


////////////////////////

xercesc_2_4::XercesDOMParser* parser = new
xercesc_2_4::XercesDOMParser();


parser->setValidationScheme(xercesc_2_4::XercesDOMParser: :Val_Never);
parser->setDoNamespaces(false);

xercesc_2_4::ErrorHandler* errHandler = (xercesc_2_4::ErrorHandler*)
new xercesc_2_4::HandlerBase();

parser->setErrorHandler(errHandler);

string metaDataFile = GetMetadataFileName(submissionID);

try
{
parser->parse(metaDataFile.c_str());
}

catch (const xercesc_2_4::XMLException& toCatch)
{
char* message =
xercesc_2_4::XMLString::transcode(toCatch.getMessa ge());
std::cout << "Exception message is: \n" << message << "\n";
xercesc_2_4::XMLString::release(&message);
delete parser;
delete errHandler;
}

catch (const xercesc_2_4:OMException& toCatch)
{
char* message = xercesc_2_4::XMLString::transcode(toCatch.msg);
std::cout << "Exception message is: \n" << message << "\n";
xercesc_2_4::XMLString::release(&message);
delete parser;
delete errHandler;
}

catch (...)
{
std::cout << "Unexpected Exception \n";
delete parser;
delete errHandler;
}

xercesc_2_4:OMDocument* xmlDoc = parser->getDocument();

if( NULL == xmlDoc )
{
std::cout<<"xml doc is null, quit\n";
delete parser;
delete errHandler;
}


xercesc:OMNodeList* list;
xercesc:OMNode* node;
const XMLCh* n;
char* xmlval = "";
string szXmlVal = "";

list = xmlDoc->getElementsByTagName(
XMLString::transcode("SubmissionDate") );
node = list->item(0);
if( xercesc:OMNode::ELEMENT_NODE == node->getNodeType() )
{
n = node->getFirstChild()->getNodeValue();
xmlval = xercesc_2_4::XMLString::transcode(n);
szXmlVal = xmlval;
xercesc_2_4::XMLString::release(&xmlval);
}


delete parser;
delete errHandler;
return szXmlVal;


/////////

Enda Mannion

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory leak even after deleting memory pointers from vector cham C++ 5 09-25-2008 10:30 AM
Leak or no leak ?? Richard Heathfield C Programming 4 07-10-2006 11:37 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Dynamic memory allocation and memory leak... s.subbarayan C Programming 10 03-22-2005 02:48 PM
Memory leak??? (top reporting high memory usage under Solaris) Mark Probert Ruby 4 02-09-2005 06:13 PM



Advertisments