Mike Ellery wrote:
The docs for XalanTransformer::initialize say --
void XalanTransformer::initialize ( MemoryManagerType & theManager
= XalanMemMgrs::getDefaultXercesMemMgr() ) [static]
Initialize Xalan.
Should be called only once per process before creating any instances of
XalanTransformer. This call is not thread-safe, so you must serialize
any calls to it, and you must track the initialization state, so you do
not call it more than once.
------
My application is a server, and it only intermittently needs to call the
xerces/xalan stuff to serialize current state. I'd prefer to initialize
these libraries only when I need them and then release them when I'm
done (thus getting back any memory that they might be holding on to).
So, I tried just doing the initialization and termination before and
after my serialization:
//initialization:
XMLPlatformUtils::Initialize();
XalanTransformer::initialize();
//DO SERIALIZATION WORK
//termination
XalanTransformer::terminate();
XMLPlatformUtils::Terminate();
XalanTransformer::ICUCleanUp();
This violates the docs for initialize, which will be called here each
time I try to serialize, but my application does not crash with my basic
tests.
What you're doing is OK, so perhaps we need to make the documentation more
explicit. What you cannot do is call XalanTransformer::initialize() a
second time, without an intervening call to XalanTransformer::terminate().
However, you should be very careful about calling
XalanTransformer::ICUCleanup(), because it can cause problems. Please read
the documentation about static cleanup of the ICU, which is documented here:
http://icu.sourceforge.net/apiref/icu4c/uclean_8h.html#93f27d0ddc7c196a1da864763f2d8920
Xalan-C does not take care of calling u_init() for you -- you must do it
yourself.
However, you might want to reconsider this strategy, because the amount of
work done in both Xerces-C and Xalan-C during static initialization is
significant, and doing it over and over again may not be the best strategy
for optimal performance.
Dave