[jdom-interest] Namespaces accumulation bug in SAXHandler
Alexander A. Rudnev
rudnev at alazarllc.com
Tue Jun 12 21:29:36 PDT 2001
Hi, I've encountered some problem with performance and found that possible reason (most probably it is not important and I'm wrong here, I'll figure it out tomorrow, but anyway, it's kind of performance/memory leak) is managing of "availableNamespaces" in SAXHandler. For example, if we declare some namespace in the root element and then all nested elements have this namespace, then for every nested element new copy of the namespace will be added to the "availableNamespaces" and will not be removed from it until the end of the parsing process. This is because element's namespace is added to the "availableNamespaces" every time on "startElement", but only "additionalNamespaces" are removed on "endElement".
Possible fix is to add element's namespace conditionally, say in such a way
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts)
throws SAXException {
...
// Remove this namespace from those in the temp declared list
if (declaredNamespaces.size() > 0) {
if(declaredNamespaces.remove(elementNamespace)) {
// It's now in available scope
availableNamespaces.addFirst(elementNamespace);
}
}
...
, but actually I did not think about it a lot.
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20010613/8899341b/attachment.htm
More information about the jdom-interest
mailing list