your program has a very common bug: you call XMLPlatformUtils::Terminate before the static objects (like MemBufInputSource) have gone out of scope. So when the destructor is invoked, it doesn't find the global state it relies on (the error is not that fEncoding is NULL, it's that fMemoryManager is pointing to deallocated memory). So you should add a { } block between Initialize and Terminate to be sure to delete the objects in the stack.
As for the memory leaks, given the presence of global state, it's better if you do the Checkpoint before running XMPlatformUtils::Initialize and do the Difference after you have called XMLPlatformUtils::Terminate
Alberto
At 13.27 13/04/2004 +0300, Nedelcho Stanev wrote:
Hello All,
I have problem using xerces 2.5.0 compiled with Visual Studio .Net on Windows 2000 Pro. I have this small source :
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { XMLPlatformUtils::Initialize(); int nRetCode = 0; CString mem = "<?xml version=\"1.0\" standalone=\"no\" ?><Operation type=\"CheckID\"></Operation>"; #ifdef _DEBUG CMemoryState oldMemState, newMemState, diffMemState; oldMemState.Checkpoint(); #endif MemBufInputSource memBufIS((const XMLByte*)mem.GetBuffer(), mem.GetLength(), "test", false); XercesDOMParser *domParser = new XercesDOMParser; domParser->parse(memBufIS); delete domParser; domParser = NULL; #ifdef _DEBUG newMemState.Checkpoint(); if( diffMemState.Difference( oldMemState, newMemState ) ) { TRACE( "Memory leaked!\n" ); diffMemState.DumpStatistics(); } #endif XMLPlatformUtils::Terminate(); return nRetCode; }
Using CMemoryState in this code, i see that after deleting of parser i still have memory leaks:
>> Memory leaked! >> 0 bytes in 0 Free Blocks. >> 660 bytes in 31 Normal Blocks. >> 0 bytes in 0 CRT Blocks. >> 0 bytes in 0 Ignore Blocks. >> 0 bytes in 0 Client Blocks. >> Largest number used: 208270 bytes. >> Total allocations: 208270 bytes.
I try lot of ways to do this parsing from buffer, but without any success, i still have this leaks and second, when i quit from program where desctructor of MemBufInputSource is executed program crash in destructor of InputSource on this place :
fMemoryManager->deallocate(fEncoding);
where fEncoding is NULL.I think will be better if before to try to release memory some check will be performed , like
if(fEncoding) fMemoryManager->deallocate(fEncoding);
about problem with memory leak i still didn't look where is the prob, so if someone can help i will be happy :)
decho
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]