[xml] xmlInitParser: Necessary or not?



Hello,

I understand that xmlCleanupParser should be called to clean up after libxml and free allocated global 
memory. However, xmlCleanupParser only works if the parser has been previously initialized. The only way to 
do so is to call xmlInitParser (see source for details).

Now I find that many functions call xmlInitParser automatically (htmlNodeDump, htmlReadMemory, to name but a 
few) and make xmlCleanupParser work. On the other hand, many functions allocate global variables and do not 
call xmlInitParser. As a result, xmlCleanupParser will not work. So if an app uses those functions only and 
does not call xmlInitParser separately, its call to xmlCleanupParser will have no effect and the application 
will leak memory.

Questions:

* Is it always recommended or even necessary to call xmlInitParser regardless of which functions are used?

* The documentation suggests to call xmlInitParser "once before processing in case of use in multithreaded 
programs." As demonstrated above, it might be necessary to call it even in single-threaded programs. Is this 
not a documentation error?

* xmlInitParser and xmlCleanupParser cover libxml. Do I need to take care of additional initialization and 
finalization besides these two in libxml?

* Can I expect similar problems in libxslt, too? Which init/finalize functions should I call for libxslt?

Any light on these issues is much appreciated.

Many thanks,

Ralf




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]