-----Original Message-----
From: Michael Snebang [mailto:[EMAIL PROTECTED]]
Sent: 15. august 2001 12:58
To: [EMAIL PROTECTED]
Subject: Memory leak when parsing from a MemBufInputSource
In my program I am using a SAXParser and a MemBufInputSource to parse a XML string. When I repeat this a number of times, it seems to use memory.
I am using Windows 2000, MS VC++ 6 sp. 4 and xerces 1.5.1.
I have reproduced the problem with the MemParse sample program:
If I add a loop around the parser creation and parse part, it uses apr. 1.2 K pr. itteration (based on Windows Task Manager figures)
for(int i=0;i<1000;i++)
{
//
// Create a SAX parser object. Then, according to what we were told on
// the command line, set it to validate or not.
//
SAXParser parser;
parser.setValidationScheme(valScheme);
parser.setDoNamespaces(doNamespaces);
parser.setDoSchema(doSchema);//
// Create our SAX handler object and install it on the parser, as the
// document and error handlers.
//
MemParseHandlers handler;
parser.setDocumentHandler(&handler);
parser.setErrorHandler(&handler);//
// Create MemBufferInputSource from the buffer containing the XML
// statements.
//
// NOTE: We are using strlen() here, since we know that the chars in
// our hard coded buffer are single byte chars!!! The parameter wants
// the number of BYTES, not chars, so when you create a memory buffer
// give it the byte size (which just happens to be the same here.)
//
MemBufInputSource* memBufIS = new MemBufInputSource
(
(const XMLByte*)gXMLInMemBuf
, strlen(gXMLInMemBuf)
, gMemBufId
, false
);//
// Get the starting time and kick off the parse of the indicated
// file. Catch any exceptions that might propogate out of it.
//
unsigned long duration;
try
{
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
parser.parse(*memBufIS);
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
duration = endMillis - startMillis;
}catch (const XMLException& e)
{
cerr << "\nError during parsing memory stream:\n"
<< "Exception message is: \n"
<< StrX(e.getMessage()) << "\n" << endl;
return -1;
}// Print out the stats that we collected and time taken.
cout << "\nFinished parsing the memory buffer containing the following "
<< "XML statements:\n\n"
<< gXMLInMemBuf
<< "\n\n\n"
<< "Parsing took " << duration << " ms ("
<< handler.getElementCount() << " elements, "
<< handler.getAttrCount() << " attributes, "
<< handler.getSpaceCount() << " spaces, "
<< handler.getCharacterCount() << " characters).\n" << endl;
}If I change the code to parse from a file instead, there is no memory leaks.
Am I missing something, or is it a bug?
Michael Snebang
System Developer
Tele Denmark Communications
Title: Memory leak when parsing from a MemBufInputSource
Hi
Michael,
Do you
ever delete memBufIS in the for loop
?
/Christoffer
- Memory leak when parsing from a MemBufInputSource Michael Snebang
- RE: Memory leak when parsing from a MemBufInput... Christoffer Dam Bruun
- RE: Memory leak when parsing from a MemBufInput... Erik Rydgren
- RE: Memory leak when parsing from a MemBufInput... Michael Snebang