Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Optimizing code for load in MSXML 4.0

From: malhenry@-----------.---------.---
To: 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!!


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent