Hey Jason,
Jason E. Stewart wrote:
According to the docs:
Users must call the release() function when finished using any
objects that were created by the DOMImplementation::createXXXX
(e.g. DOMBuilder, DOMWriter, DOMDocument, DOMDocumentType).
So here is the code:
XMLCh xfoo[] = {chLatin_f, chLatin_o, chLatin_o, chNull};
DOMImplementation* impl =
DOMImplementationRegistry::getDOMImplementation(X("Core"));
while (1)
{
try
{
DOMDocumentType* dt = impl->createDocumentType(xfoo,xfoo,xfoo);
dt->release();
}
catch (...)
{
XERCES_STD_QUALIFIER cerr << "An error occurred creating the document"
<< XERCES_STD_QUALIFIER endl;
errorCode = 3;
}
}
But this leaks.
Replacing 'dt->release()' with 'delete dt' has no affect.
This will release the memory associated with the node itself but *not*
any memory that the node new's with the memory manager. If you take a
look in the code you will find a few places that that happens. The
classic that people have found in the past is for the element node,
where we new an attribute list in the constructor.
The docs also say:
When a DOMDocumentType has been inserted into a DOMDocument and thus
has a owner, it will then be released automatically when its owner
document is released.
So I added:
DOMDocument* doc = impl->createDocument(0,xfoo,dt);
doc->release();
in place of the 'dt->release()' but this had no affect.
However, removing the creation of the DocumentType and calling:
DOMDocument* doc = impl->createDocument(0,xfoo,0);
doc->release();
Does *not* leak.
Is this a real leak or am I missing something? How is one supposed to
deal with DOMDocumentType memory?
Nope, not a real leak. When you free the document the memory pools that
were used to new things from are deleted so it cleans up all the things
like the attribute list from the creation of an element.
I will add a blog entry describing this in a bit more depth.
Cheers,
Gareth
--
Gareth Reakes, Managing Director Parthenon Computing
+44-1865-811184 http://blogs.parthcomp.com/xerces
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]