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

P

polism

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
 
M

Martin Honnen

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

polism

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

Mike
 
M

Martin Honnen

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top