Re: Memory leak in loadxml?
Quote:
Originally Posted by LaxRoth
Hi, i'm trying to load an xml document from C++ with:
MSXML::IXMLDOMDocumentPtr pXMLDocument (__uuidof (MSXML:OMDocument)); // main document parsed
hr = pXMLDocument->loadXML (BSTRTemp); /* trying parse string, if success, we have doc object*/
this method uses offensive memory. i have xml files that are about 100MB size.
i feel the function does not clear the memory. anyone an idea?
if i load 3 times the same file, my memory is full.
suggestion? is there a free method or something?
thank you,
lutz
:mad:
at starting Initializes the COM library with CoInitialize(NULL)
after finishing your xml work
Closes the COM library
by CoUnInitialize()
Deallocates a string allocated Memory
use ::SysFreeString(BSTR);
check for CString that if your allocated memory all are free or not
then check whether you are allocating memory with new or not if yes
Don't forget to Release it use delete []
if still proble let me know
//to release BSTR memory
Re: Memory leak in loadxml?
Hi, all done. sorry, not written explicitly.
currently:
hr = pXMLDocument->load (filename); /* trying parse string, if success, we have doc object*/
i iterate over a function that creates smartptr this way:
MSXML::IXMLDOMDocumentPtr pXMLDocument (__uuidof (MSXML::DOMDocument));
looks like this:
CoInitialize(NULL);
--> Iterate 200x
--> MSXML::IXMLDOMDocumentPtr pXMLDocument
---> pXMLDocument.load(filename)
---> do some blaaaaah
CoUninitialize();
still memory leaks. i tried to create a global pointer to pXMLDocument, same effect. does ist store internal data, how can i free it....
:wave:
Re: Memory leak in loadxml?
Did you do pXMLDocument.Release() at the end? Otherwise that object doesn't get freed properly.
Re: Memory leak in loadxml?
hi, i used smartpointer. this type releases itself when my function is finished. i see him walking through release. well, i will try to use normal com pointer. but i guess thats not it.
:sick:
Re: Memory leak in loadxml?
Quote:
Originally Posted by LaxRoth
hi, i used smartpointer. this type releases itself when my function is finished. i see him walking through release. well, i will try to use normal com pointer. but i guess thats not it.
:sick:
Fine do one thing
it happens due to LoadXml
when you are loading a xml by LoadXml
after finishing your work just check it out still file exist and that's why i think u rgetting error
it's aloop hole of microsoft
better
after finishing your work do this
pXMLDocument->loadXML(CComBSTR(""), &bSuccessful );
pXMLDocument = NULL;
::CoUninitialize();
Load a empty string
and your memory leakage will remove.
hopefully this will help you
Re: Memory leak in loadxml?
hi,
if i call pXMLDocument->loadXML(BSTR(""));
i get some exceptions:
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
memory still remains high.
Re: Memory leak in loadxml?
Quote:
Originally Posted by LaxRoth
hi,
if i call pXMLDocument->loadXML(BSTR(""));
i get some exceptions:
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
Nicht abgefangene Ausnahme in kp32sqke.exe (KERNEL32.DLL): 0xE0000001: (kein Name).
memory still remains high.
are you sure.
check it out once again and this code is one of my working project
Re: Memory leak in loadxml?
very sure.
currently i import msxml.dll:
#import "msxml.dll" named_guids
create smartptr:
MSXML::IXMLDOMDocumentPtr pXMLDocument (__uuidof (MSXML::DOMDocument)); // main document parsed
load xml from file:
hr = pXMLDocument->load (filename); /* trying parse string, if success, we have doc object*
your suggestion:
pXMLDocument->loadXML("");
pXMLDocument = NULL;
i have also tried with MSXML2:: namespace, same effect.
its too my working project...
:wave:
Re: Memory leak in loadxml?
Quote:
Originally Posted by LaxRoth
very sure.
currently i import msxml.dll:
#import "msxml.dll" named_guids
create smartptr:
MSXML::IXMLDOMDocumentPtr pXMLDocument (__uuidof (MSXML::DOMDocument)); // main document parsed
load xml from file:
hr = pXMLDocument->load (filename); /* trying parse string, if success, we have doc object*
your suggestion:
pXMLDocument->loadXML("");
pXMLDocument = NULL;
i have also tried with MSXML2:: namespace, same effect.
its too my working project...
:wave:
due to xml version effect check with this
#import <msxml.dll> named_guids
using namespace MSXML;
hr = spDocument.CoCreateInstance(CLSID_DOMDocument);
hr = spDocument->load(CComVariant(strpath), &bSuccess);
if still getting problem
please post your code
Re: Memory leak in loadxml?
Quote:
Originally Posted by humptydumpty
due to xml version effect check with this
#import <msxml.dll> named_guids
using namespace MSXML;
hr = spDocument.CoCreateInstance(CLSID_DOMDocument);
hr = spDocument->load(CComVariant(strpath), &bSuccess);
if still getting problem
please post your code
sorry what is spDocument ?
Re: Memory leak in loadxml?
Quote:
Originally Posted by LaxRoth
sorry what is spDocument ?
spDocument Object of IXMLDOMDocument
CComPtr<IXMLDOMDocument> spDocument;
Re: Memory leak in loadxml?
Quote:
Originally Posted by LaxRoth
hi, i used smartpointer. this type releases itself when my function is finished. i see him walking through release. well, i will try to use normal com pointer. but i guess thats not it.
:sick:
My point is that if you do everything in main(), then the document won't get released until after main() has finished and so it didn't get released before calling CoUnintialize.
Re: Memory leak in loadxml?
hi, i see the com pointer walking through release...its not called in main function. i will try in separate project. meanwhile i post som xml...is this correct syntax???
or maybe the files are wrong?
<?xml version='1.0' encoding='Windows-1250'?>
<connection>
<TXTXMLRow refid='1' ID='dpe' DbSystem='SQLServer' Db='dpe' ConnType='ADO' DSN='nblb' PhysUser='sa' PhysPwd='sa' active='No' activedb='No'/>
<TXTXMLRow refid='3' ID='ADIMP' DbSystem='Sybase' Db='ADIMP' ConnType='ODBC' DSN='ADIMP' PhysUser='sa' PhysPwd='opensoft' active='No' activedb='No'/>
<TXTXMLRow refid='4' ID='ADROB' DbSystem='Sybase' Db='ADROB' ConnType='ODBC' DSN='ADROB' PhysUser='sa' PhysPwd='opensoft' active='No' activedb='No'/>
</connection>
Re: Memory leak in loadxml?
Quote:
Originally Posted by LaxRoth
hi, i see the com pointer walking through release...its not called in main function. i will try in separate project. meanwhile i post som xml...is this correct syntax???
or maybe the files are wrong?
<?xml version='1.0' encoding='Windows-1250'?>
<connection>
<TXTXMLRow refid='1' ID='dpe' DbSystem='SQLServer' Db='dpe' ConnType='ADO' DSN='nblb' PhysUser='sa' PhysPwd='sa' active='No' activedb='No'/>
<TXTXMLRow refid='3' ID='ADIMP' DbSystem='Sybase' Db='ADIMP' ConnType='ODBC' DSN='ADIMP' PhysUser='sa' PhysPwd='opensoft' active='No' activedb='No'/>
<TXTXMLRow refid='4' ID='ADROB' DbSystem='Sybase' Db='ADROB' ConnType='ODBC' DSN='ADROB' PhysUser='sa' PhysPwd='opensoft' active='No' activedb='No'/>
</connection>
Better it you put your file.
then it's easy to find actual error.
because all possibilities are discussed here.
now without seen the project i don't think that anyone can tell you exact problem.
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