Xerces-C docs say an application should never new a DOM object since "this
will
greatly confuse the automatic memory management". I'd appreciate if someone
could elaborate on how Xerces memory management could be thrown off by an
application newing a DOM instance.
It seems Xerces reference counting should work even if a DOM instance is
new'd.
The new will increment the reference count and the reference count cannot go
to
zero before a corresponding delete is done.
Below is a simple scenario in which a DOM_Node pointer works. Why won't it
work
in other situations?
One reason it would be nice to use pointers is to remove dependencies on
Xerces
headers by using DOM_Node * instead of DOM_Node data members.
Thanks,
Zartaj
#include <string>
#include <iostream>
#include <util/PlatformUtils.hpp>
#include <dom/DOM_DOMException.hpp>
#include <dom/DOM_Node.hpp>
#include <dom/DOM_Document.hpp>
#include <dom/DOMString.hpp>
DOM_Node *fp(const std::string &text)
{
DOM_Document d = DOM_Document::createDocument();
DOM_Node n = d.createTextNode(text.c_str());
// n.fImpl->nodeRefCount = 2
DOM_Node *np = new DOM_Node(n);
// np->fImpl->nodeRefCount = 3
std::cout << "fp: " << np->getNodeValue().transcode() << "\n";
return np;
}
int main(int argc, char *argv[])
{
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
std::cerr << "main: Error during initialization! :\n";
return 1;
}
DOM_Node *np = fp("NewTextNode");
// np->fImpl->nodeRefCount = 1
std::cout << "main: " << np->getNodeValue().transcode() << "\n";
delete np;
return 0;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]