Abhinav Kishore Srivastava wrote:
Dear David Bertoni,
Thanks for the suggestion. I removed the 'new' call from my code and created the object of membuf and XercesDOMParser as you suggested but still there is a memory leak. After the analysis of the process log I saw that the memory leak is happening when I am calling "m_domParser->parse(membuf);". I guess the memory allocated while parsing is not getting released.
Can you suggest me the different ways to release the memory allocated with
parsing? To be of safer side I am calling the following after the 'parse'
function -
DOMDocument* m_doc;
m_doc = m_domParser->adoptDocument();
if (m_domParser!=0)
{
m_domParser = 0;
}
if(m_doc!=0)
{
m_doc->release();
delete m_doc;
m_doc = 0;
I can't believe this will work. You can't call delete on m_doc and not
corrupt the heap of your application. You must only use m_doc->release();
Any decent heap debugger will report this as a problem. You should see
if your platform supports heap debugging. On Linux, you can use
Valgrind with the memcheck tool. On Windows, an application linked with
the debug C run-time will report such errors. On AIX, there are
environment variables you can set to control heap debugging.
Note that all of these previous heap checking tools also support dumping
leaked memory blocks. I urge you to consider using such a tool, as it
will save you a lot of time and effort.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]