Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - RE: Optimizing code for load in MSXML 4.0 Optimizing code for load in MSXML 4.0To: NULL Date: 12/6/2005 9:12:00 AM I am using MSXML 4.0 with VC++ 6.0 and am trying to optimize my code which
processes xml files. My real question is does the load method below free the
memory used by the prior xml doc that was loaded?
My original pseudo code was:
Loop
//start constructor
::CoInitialize(NULL);
hr = ::CoCreateInstance(...);
//end constructor
// process the xml
...
CHECKHR(pDoc->put_async(VARIANT_FALSE));
CHECKHR(pDoc->put_validateOnParse(VARIANT_FALSE));
// Load xml document from the given URL or file path
VariantInit(&vURL);
vURL.vt = VT_BSTR;
V_BSTR(&vURL) = pBURL;
CHECKHR(pDoc->load(vURL, &vb));//****KEY call
CHECKHR(CheckLoad(pDoc));
CleanUp:
SAFERELEASE(pXMLError);
...
//start destructor
if (m_pDoc)
{
unsigned long ul;
ul = (m_pDoc)->Release();
m_pDoc = NULL;
}
// free the string allocated by StringToBSTR that contains xml filename
if (m_pBURL != NULL)
::SysFreeString(m_pBURL);
::CoUninitialize(); //returns a void
//end destructor
//ENDLOOP
What I did to try to improve the code above was to move the constructor and
destructor OUT of the loop so that they should only get called once. I added
to the bottom of the loop a if (m_pBURL != NULL)
::SysFreeString(m_pBURL); so that the memory associated with the xml
filename would be freed.
I thought the load call would free the memory used by the prior xml doc
processed. However, I am seeing a HIGHER usage of memory outstanding with
the second version of my code using a memory analysis tool.
Am I mistaken that load will also free memory? Should I go back to the
original version of my code which seems inefficient to initialize and
de-initialize com for every xml file I must process? Any advice?
Thanks!!
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
