CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Join Date
    Mar 2003
    Posts
    62

    Angry Memory leak in loadxml?

    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



  2. #2
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb 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


    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

  3. #3
    Join Date
    Mar 2003
    Posts
    62

    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:OMDocument));



    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....

  4. #4
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    Re: Memory leak in loadxml?

    Did you do pXMLDocument.Release() at the end? Otherwise that object doesn't get freed properly.
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  5. #5
    Join Date
    Mar 2003
    Posts
    62

    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.



  6. #6
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb 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.


    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

  7. #7
    Join Date
    Mar 2003
    Posts
    62

    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.

  8. #8
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb 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

  9. #9
    Join Date
    Mar 2003
    Posts
    62

    Re: Memory leak in loadxml?

    very sure.

    currently i import msxml.dll:

    #import "msxml.dll" named_guids


    create smartptr:

    MSXML::IXMLDOMDocumentPtr pXMLDocument (__uuidof (MSXML:OMDocument)); // 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...


  10. #10
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb 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:OMDocument)); // 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...
    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
    Last edited by humptydumpty; July 19th, 2005 at 07:30 AM.

  11. #11
    Join Date
    Mar 2003
    Posts
    62

    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 ?

  12. #12
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb Re: Memory leak in loadxml?

    Quote Originally Posted by LaxRoth
    sorry what is spDocument ?
    spDocument Object of IXMLDOMDocument
    CComPtr<IXMLDOMDocument> spDocument;

  13. #13
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    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.


    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.
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  14. #14
    Join Date
    Mar 2003
    Posts
    62

    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>

  15. #15
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb 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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured