John Doe wrote:
Hi, this is the second time I send this message, sorry for that, its just
that I am not sure it got sent
the first time, since I didn't receive any responces.
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.
There was a long discussion about this just a few weeks ago:
http://marc.theaimsgroup.com/?l=xerces-c-dev&m=116592343116092&w=2
The bottom line is that you will need to release the parent DOMDocument
instance to recover all of the memory.
Also, it looks like you're using one DOMDocument instance as a factory,
creating a large tree, then importing that entire tree into another
document. You might want to consider re-factoring your code so you always
create the new nodes in the document that's the final destination of the
nodes, since that is much more efficient.
Dave