shishir
2011-06-24 07:16:36 UTC
MSXML6 Memory Leaks - Recursive implementation for XML parsing
Hi All,
I am developing a C++ application that uses MSXML6 to parse an XML.
The XML contains a collection of <Record> nodes .e.g.
<Root>
<Record id=1>...</Record>
<Record id=2>...</Record>
<Record id=3>...</Record>
<Record id=4>...</Record>
<Record id=5>...</Record>
..
...
</Root>
My application is a dialog box that has a ListView, a "Next" and
"Previous" button. The application -
1. Reads a set(fixed number) of these <Record> nodes and displays
them in a ListView
2. When the end user clicks the "Next" button then the application
clears the ListView, reads the next set of <Record> nodes and
populates the ListView with the new set of records.
3. This way my application always displays a fixed set of <Record>
nodes only.
The schema of the <Record> node however is unknown so to parse this
XML the C++ application will have to -
1. Retrieve a collection of <Record> nodes
2. Iterate the collection of <Record> nodes
3. Retrieve a collection of the child nodes in each <Record> node
4. Iterate each child node
5. Check if the child node has any childs
6.
a. If the child does not have any node display the "name" and
"value" of the node.
b. If the child has nodes then repeat steps 3,4, 5 and 6.
(Recursive function implementation)
Code
=============
void CMyDlg::PopulateLogFileData(std::vector<struct stctLogDetails >
&f_vctAllDetailValue,
MSXML2::IXMLDOMNodePtr f_pChild,
int
f_ExtractData,
int
f_nReadCount)
{
int i_Cnt = 0;
for (;NULL != f_pChild; f_pChild = f_pChild->nextSibling)
{
MSXML2::IXMLDOMNodePtr pChild = f_pChild->firstChild;
CComBSTR l_bstr;
f_pChild->get_nodeName(&l_bstr);
MSXML2::IXMLDOMNodePtr l_pNodeBody = NULL;
l_pNodeBody = f_pChild->GetparentNode();
CComBSTR bs;
l_pNodeBody->get_nodeName(&bs);
m_pXMLDOMList = l_pNodeBody->GetchildNodes();
...
...
...
PopulateLogFileData(f_vctAllDetailValue,pChild,f_ExtractData,f_nReadCount);
}
}
My code uses the smart pointers for MSXML (available from #import of
the "MSXML6.dll") and BSTRs.
Memory Leak Problem
======================
I observe that with every click of "Next" button my memory consumption
keeps increasing and it never comes down. I have used smart pointers
for "MSXML" and BSTR so I am not leaking any interfaces or memory so I
am unable to understand the reason behind the memory consumption. Even
if we assume that the memory consumption may go up due to the
Recursive function call implementation still the memory should be
released when the call completes.
Does anybody have any idea on this behavior of MSXML.
Regards,
Shishir Srivastav
Hi All,
I am developing a C++ application that uses MSXML6 to parse an XML.
The XML contains a collection of <Record> nodes .e.g.
<Root>
<Record id=1>...</Record>
<Record id=2>...</Record>
<Record id=3>...</Record>
<Record id=4>...</Record>
<Record id=5>...</Record>
..
...
</Root>
My application is a dialog box that has a ListView, a "Next" and
"Previous" button. The application -
1. Reads a set(fixed number) of these <Record> nodes and displays
them in a ListView
2. When the end user clicks the "Next" button then the application
clears the ListView, reads the next set of <Record> nodes and
populates the ListView with the new set of records.
3. This way my application always displays a fixed set of <Record>
nodes only.
The schema of the <Record> node however is unknown so to parse this
XML the C++ application will have to -
1. Retrieve a collection of <Record> nodes
2. Iterate the collection of <Record> nodes
3. Retrieve a collection of the child nodes in each <Record> node
4. Iterate each child node
5. Check if the child node has any childs
6.
a. If the child does not have any node display the "name" and
"value" of the node.
b. If the child has nodes then repeat steps 3,4, 5 and 6.
(Recursive function implementation)
Code
=============
void CMyDlg::PopulateLogFileData(std::vector<struct stctLogDetails >
&f_vctAllDetailValue,
MSXML2::IXMLDOMNodePtr f_pChild,
int
f_ExtractData,
int
f_nReadCount)
{
int i_Cnt = 0;
for (;NULL != f_pChild; f_pChild = f_pChild->nextSibling)
{
MSXML2::IXMLDOMNodePtr pChild = f_pChild->firstChild;
CComBSTR l_bstr;
f_pChild->get_nodeName(&l_bstr);
MSXML2::IXMLDOMNodePtr l_pNodeBody = NULL;
l_pNodeBody = f_pChild->GetparentNode();
CComBSTR bs;
l_pNodeBody->get_nodeName(&bs);
m_pXMLDOMList = l_pNodeBody->GetchildNodes();
...
...
...
PopulateLogFileData(f_vctAllDetailValue,pChild,f_ExtractData,f_nReadCount);
}
}
My code uses the smart pointers for MSXML (available from #import of
the "MSXML6.dll") and BSTRs.
Memory Leak Problem
======================
I observe that with every click of "Next" button my memory consumption
keeps increasing and it never comes down. I have used smart pointers
for "MSXML" and BSTR so I am not leaking any interfaces or memory so I
am unable to understand the reason behind the memory consumption. Even
if we assume that the memory consumption may go up due to the
Recursive function call implementation still the memory should be
released when the call completes.
Does anybody have any idea on this behavior of MSXML.
Regards,
Shishir Srivastav