This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > February 2005 > Is there a memory leak with load/loadxml?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Is there a memory leak with load/loadxml?
Jerry

2005-02-18, 6:29 pm

Hi All,
I seem to have a basic problem with XML DOM Parser. There seem to be a
memory leak in the MSXML3 and MSXML4 parsers. The memory goes on increasing
and does not come down. I have an application which would be processing 10K
XML documents 5000 times. This inceases the memory to around 70MB and does
not bring it down. Am I doing something wrong here. I read some article
which talks about the latency in XML freeing its memory. But I waited and it
never came down. I tried MSXML3 as well as MSXML4 with same results
Here is the code I am using;
for (int i=0; i < 5; i++)

{

MSXML2::IXMLDOMDocumentPtr pXMLDoc = NULL;

HRESULT hr = pXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));

pXMLDoc->async = VARIANT_FALSE; // default - true,

hr = pXMLDoc->load("c:\\test.xml");


if (hr != VARIANT_TRUE)

{

MSXML2::IXMLDOMParseErrorPtr pError;

pError = pXMLDoc->parseError;

_bstr_t parseError =_bstr_t("At line ")+ _bstr_t(pError->Getline()) +
_bstr_t("\n")+ _bstr_t(pError->Getreason());

MessageBox(NULL,parseError, "Parse Error",MB_OK);

return 0;

}

else {

//do something

}

}



Thanks in advance

Jerry


Martin Honnen

2005-02-18, 6:29 pm



Jerry wrote:


> Here is the code I am using;
> for (int i=0; i < 5; i++)
>
> {
>
> MSXML2::IXMLDOMDocumentPtr pXMLDoc = NULL;
>
> HRESULT hr = pXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));


I can't really help with memory issues when using MSXML from C++ but do
you need to create a new document inside the loop body? It could suffice
to create one DOMDocument40 instance outside of the loop and then in the
loop use that instance to load the different XML files as needed,
extract the data and reuse the instance.



--

Martin Honnen
http://JavaScript.FAQTs.com/
Evgeny Bogolyubov

2005-02-18, 6:29 pm

Hi Jerry,

I think you need to do something like that at the end of your function:

clean:
if (pxmldoc)
{
pxmldoc->Release();
}

Basically you need to release all objects you get from MSXML.

I hope this helps.

Best regards,
Evgeny.

"Jerry" <jerrio@hotmail.com> wrote in
news:u2UnoKcFFHA.392@TK2MSFTNGP14.phx.gbl:

> Hi All,
> I seem to have a basic problem with XML DOM Parser. There seem to be a
> memory leak in the MSXML3 and MSXML4 parsers. The memory goes on
> increasing and does not come down. I have an application which would
> be processing 10K XML documents 5000 times. This inceases the memory
> to around 70MB and does not bring it down. Am I doing something wrong
> here. I read some article which talks about the latency in XML freeing
> its memory. But I waited and it never came down. I tried MSXML3 as
> well as MSXML4 with same results Here is the code I am using;
> for (int i=0; i < 5; i++)
>
> {
>
> MSXML2::IXMLDOMDocumentPtr pXMLDoc = NULL;
>
> HRESULT hr = pXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));
>
> pXMLDoc->async = VARIANT_FALSE; // default - true,
>
> hr = pXMLDoc->load("c:\\test.xml");
>
>
> if (hr != VARIANT_TRUE)
>
> {
>
> MSXML2::IXMLDOMParseErrorPtr pError;
>
> pError = pXMLDoc->parseError;
>
> _bstr_t parseError =_bstr_t("At line ")+ _bstr_t(pError->Getline()) +
> _bstr_t("\n")+ _bstr_t(pError->Getreason());
>
> MessageBox(NULL,parseError, "Parse Error",MB_OK);
>
> return 0;
>
> }
>
> else {
>
> //do something
>
> }
>
> }
>
>
>
> Thanks in advance
>
> Jerry
>
>


Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews