importNode() / release() memory growth problem in Xerces-C++

Discussion in 'XML' started by polism@gmail.com, Dec 18, 2006.

  1. Guest

    Hi,
    I have the following simple code, using xerces running on my windows.
    This demo compiles and runs normally, but when I open my Task Manager,
    I see a constant memory growth of my process, and I dont understand
    why.

    //***********************************************
    XMLPlatformUtils::Initialize();
    DOMImplementation impl =
    DOMImplementationRegistry::getDOMImplementation(...);
    DOMDocument* doc1 = impl->createDocument(...);
    DOMDocument* doc2 = impl->createDocument(...);
    DOMElement* elem1 = doc1->createElement(...);
    DOMElement* elem2 = doc2->createElement(...);

    // get elem2 to be realy big element, so that memory leak will be more
    visible
    DOMElement* tmp = doc2->createElement(...);
    for(int i=0; i<50; i++)
    {
    elem2->appendChild(tmp);
    }

    DOMNode* node;
    while(true)
    {
    // thread sleep for 20 msec
    Sleep(20);
    node = doc1->importNode(elem2, true);
    node->release();
    }


    //****************************************************
    I understand that importNode() actualy clones the original node, but
    release() is supposed to free it, and it seems that it doesn't happen.
    What is wrong here? please help.

    thanx ahead,
    Mike
     
    , Dec 18, 2006
    #1
    1. Advertising

  2. wrote:

    > // get elem2 to be realy big element, so that memory leak will be more
    > visible
    > DOMElement* tmp = doc2->createElement(...);
    > for(int i=0; i<50; i++)
    > {
    > elem2->appendChild(tmp);
    > }


    You have just one tmp element that you append fifty times to the same
    elem2 so I am not sure why that makes elem2 really big.

    Not sure a about the memory issue, you might want to ask on the Xerces
    C++ mailing list.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 19, 2006
    #2
    1. Advertising

  3. Guest

    well, every time you appendChild, the child is added, even if it is
    pointer to the same object.

    Mike


    Martin Honnen wrote:
    > wrote:
    >
    > > // get elem2 to be realy big element, so that memory leak will be more
    > > visible
    > > DOMElement* tmp = doc2->createElement(...);
    > > for(int i=0; i<50; i++)
    > > {
    > > elem2->appendChild(tmp);
    > > }

    >
    > You have just one tmp element that you append fifty times to the same
    > elem2 so I am not sure why that makes elem2 really big.
    >
    > Not sure a about the memory issue, you might want to ask on the Xerces
    > C++ mailing list.
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    , Dec 20, 2006
    #3
  4. wrote:
    > well, every time you appendChild, the child is added, even if it is
    > pointer to the same object.


    If you have just one node you pass to appendChild fifty times then the
    node you can appendChild on will have just one child node appended. So
    it suffices to call appendChild once, doing it several times does not
    add more children, unless you created a new node to be passed in each time.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 20, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish

    performance of importNode

    Andy Fish, Nov 4, 2003, in forum: XML
    Replies:
    0
    Views:
    649
    Andy Fish
    Nov 4, 2003
  2. Generic Usenet Account

    Tracking the "memory growth" of a process

    Generic Usenet Account, Apr 5, 2004, in forum: C++
    Replies:
    5
    Views:
    466
    Kevin Goodsell
    Apr 6, 2004
  3. Generic Usenet Account

    Tracking the "memory growth" of a process

    Generic Usenet Account, Apr 5, 2004, in forum: C Programming
    Replies:
    4
    Views:
    336
    Kevin Goodsell
    Apr 6, 2004
  4. Simon Brooke
    Replies:
    10
    Views:
    1,134
    Joe Kesselman
    Mar 17, 2007
  5. yawnmoth

    unable to get importNode working

    yawnmoth, Aug 22, 2006, in forum: Javascript
    Replies:
    5
    Views:
    120
    Martin Honnen
    Aug 23, 2006
Loading...

Share This Page