EDN Admin
Well-known member
<br/>
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><br/>
<Record id=1>...</Record><br/>
<Record id=2>...</Record><br/>
<Record id=3>...</Record><br/>
<Record id=4>...</Record><br/>
<Record id=5>...</Record><br/>
..<br/>
...<br/>
</Root>
My application is a dialog box that has a ListView, a "Next" and "Previous" button. The application -<br/>
1. Reads a set(fixed number) of these <Record> nodes and displays them in a ListView<br/>
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.<br/>
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<br/>
2. Iterate the collection of <Record> nodes<br/>
3. Retrieve a collection of the child nodes in each <Record> node<br/>
4. Iterate each child node<br/>
5. Check if the child node has any childs<br/>
6. <br/>
a. If the child does not have any node display the "name" and "value" of the node.<br/>
b. If the child has nodes then repeat steps 3,4, 5 and 6. (Recursive function implementation)
<br/>
Code <br/>
=============
void CMyDlg:opulateLogFileData(std::vector<struct stctLogDetails > &f_vctAllDetailValue,<br/>
MSXML2::IXMLDOMNodePtr f_pChild, <br/>
int f_ExtractData,<br/>
int f_nReadCount)<br/>
{
int i_Cnt = 0;
<br/>
for (;NULL != f_pChild; f_pChild = f_pChild->nextSibling)<br/>
{
MSXML2::IXMLDOMNodePtr pChild = f_pChild->firstChild;
CComBSTR l_bstr;<br/>
f_pChild->get_nodeName(&l_bstr);
MSXML2::IXMLDOMNodePtr l_pNodeBody = NULL;<br/>
l_pNodeBody = f_pChild->GetparentNode();<br/>
CComBSTR bs;<br/>
l_pNodeBody->get_nodeName(&bs);<br/>
m_pXMLDOMList = l_pNodeBody->GetchildNodes();
...
...<br/>
<br/>
...
PopulateLogFileData(f_vctAllDetailValue,pChild,f_ExtractData,f_nReadCount);<br/>
}
}
My code uses the smart pointers for MSXML (available from #import of the "MSXML6.dll") and BSTRs.
<br/>
Memory Leak Problem<br/>
======================
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.
<br/>
Regards,<br/>
Shishir Srivastav
View the full article
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><br/>
<Record id=1>...</Record><br/>
<Record id=2>...</Record><br/>
<Record id=3>...</Record><br/>
<Record id=4>...</Record><br/>
<Record id=5>...</Record><br/>
..<br/>
...<br/>
</Root>
My application is a dialog box that has a ListView, a "Next" and "Previous" button. The application -<br/>
1. Reads a set(fixed number) of these <Record> nodes and displays them in a ListView<br/>
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.<br/>
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<br/>
2. Iterate the collection of <Record> nodes<br/>
3. Retrieve a collection of the child nodes in each <Record> node<br/>
4. Iterate each child node<br/>
5. Check if the child node has any childs<br/>
6. <br/>
a. If the child does not have any node display the "name" and "value" of the node.<br/>
b. If the child has nodes then repeat steps 3,4, 5 and 6. (Recursive function implementation)
<br/>
Code <br/>
=============
void CMyDlg:opulateLogFileData(std::vector<struct stctLogDetails > &f_vctAllDetailValue,<br/>
MSXML2::IXMLDOMNodePtr f_pChild, <br/>
int f_ExtractData,<br/>
int f_nReadCount)<br/>
{
int i_Cnt = 0;
<br/>
for (;NULL != f_pChild; f_pChild = f_pChild->nextSibling)<br/>
{
MSXML2::IXMLDOMNodePtr pChild = f_pChild->firstChild;
CComBSTR l_bstr;<br/>
f_pChild->get_nodeName(&l_bstr);
MSXML2::IXMLDOMNodePtr l_pNodeBody = NULL;<br/>
l_pNodeBody = f_pChild->GetparentNode();<br/>
CComBSTR bs;<br/>
l_pNodeBody->get_nodeName(&bs);<br/>
m_pXMLDOMList = l_pNodeBody->GetchildNodes();
...
...<br/>
<br/>
...
PopulateLogFileData(f_vctAllDetailValue,pChild,f_ExtractData,f_nReadCount);<br/>
}
}
My code uses the smart pointers for MSXML (available from #import of the "MSXML6.dll") and BSTRs.
<br/>
Memory Leak Problem<br/>
======================
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.
<br/>
Regards,<br/>
Shishir Srivastav
View the full article