1 Attachment(s)
Re: Memory leak in loadxml?
look at msdev 6.0 project. main file is xml.cpp.
my problem is the following: during the for loop memory consumption is high.
the app i want to dev. is a large app. CoInitialize is called at the very beginning, counit. at the end. i'm not abel to call this at runtime cause we use other com servers too.
if you compile the prog you will see that in the for loop remains memory in the parser. just place some different xml files in a directory and change the path for ::load(file).
if you do not call ::loadxml with empty string memory will stay high. i do not understand this...
1 Attachment(s)
Re: Memory leak in loadxml?
just check it out.
now i think now there is no problem .
let's check it
if still some problem let me know
Re: Memory leak in loadxml?
Quote:
Originally Posted by humptydumpty
just check it out.
now i think now there is no problem .
let's check it
if still some problem let me know
looks better, i guess there is not a problem. thank you very much!
:)
Re: Memory leak in loadxml?
Re: Memory leak in loadxml?
Hello,
I have the same problem. I've tried your solution, but it throws a lot of exceptions as mentioned by LaxRoth.
What did I do wrong?
Thanks
Re: Memory leak in loadxml?
Hi,
I am facing the same issue in my application. I have to run my application multiple time. In my app I am using 2 DOM object pointers. One for reading an XML and another for creating n writing a new XML.
Header
=========
#import <msxml4.dll>
#include <msxml.h>
MSXML2::IXMLDOMDocumentPtr m_pReadXMLDoc;
MSXML2::IXMLDOMDocumentPtr m_pWriteXMLDoc;
Inside LoadXML() I am loading the XML:
===========================
hResult = CoCreateInstance(CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument, (void **)&m_pWriteXMLDoc);
if (FAILED(hResult) || m_pWriteXMLDoc == NULL)
return false;
hResult = m_pWriteXMLDoc->put_async(VARIANT_FALSE);
if (FAILED(hResult))
{
m_pWriteXMLDoc->Release();
return false;
}
_variant_t v(FBInput_INFO_PATH);
// VARIANT_BOOL vb;
vb = m_pWriteXMLDoc->load(v);
v.Clear();
if (vb == 0)
{
m_pWriteXMLDoc->Release();
return false;
}
And in destructor I am releasing the memory as:
====================================
if(m_pReadXMLDoc)
m_pReadXMLDoc->Release();
if(m_pWriteXMLDoc)
m_pWriteXMLDoc.Release();
m_pReadXMLDoc = NULL;
m_pWriteXMLDoc = NULL;
::CoUninitialize();
But still after one iteration of the application, memory is not being released, and keep on increasing after every iteration. I also tried with:
if(m_pReadXMLDoc)
m_pReadXMLDoc->loadXML("");
if(m_pWriteXMLDoc)
m_pWriteXMLDoc->loadXML("");
Still I am having a good enough Memory leak.
Experts, plz let me know how can I get rid of this.
- Rahul
Re: Memory leak in loadxml?
Hi rahul.
As far as is rememer the problem with the memory leak was not solved. Instead, i decided to use SAX parser, not DOM parser. This works better for larger xml files. You can still try to install newest msxml parser...i don't know if they (M$) solved the problem.
Regards, laxroth
Re: Memory leak in loadxml?
I am using MS DOM XML object in my WinCE\Win Mobile based application. As you told about SAX parser, can I use same here too ???
Re: Memory leak in loadxml?
Hi Rasul.
I am not very confirm with win ce, but think this should work if you can use
dom parser and at least msxml4.
create instance:
hr = CoCreateInstance(__uuidof(SAXXMLReader40), NULL, CLSCTX_ALL, __uuidof(ISAXXMLReader),
(void **)&pReader);
you need 2 handlers: content handler & error handler
class CSaxContentHandler : public ISAXContentHandler
class CSaxErrorHandler : public ISAXErrorHandler
You have to override several methods there, please see msdn.
Then set them to pReader....
// create & set content handler
pcontentHandler = new CSaxContentHandler;
hr = pReader->putContentHandler(pcontentHandler);
// create & set error handler
perrorHandler = new CSaxErrorHandler;
hr = pReader->putErrorHandler(perrorHandler);
// read xml file
hr = pReader->parseURL(wszURL)
Content & error handler will be called from there...
Have fun :wave:
LaxRoth