import java.net.URLConnection;
import javax.imageio.ImageIO;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
this.urlCacheProtection = urlCacheProtection;
}
+ /**
+ * XML parsing can pin a web application class loader in memory. This is
+ * particularly nasty as profilers (at least YourKit and Eclispe MAT) don't
+ * idenitfy any GC roots related to this.
+ */
+ protected boolean xmlParsingProtection = true;
+ public boolean isXmlParsingProtection() { return xmlParsingProtection; }
+ public void setXmlParsingProtection(boolean xmlParsingProtection) {
+ this.xmlParsingProtection = xmlParsingProtection;
+ }
+
@Override
public void lifecycleEvent(LifecycleEvent event) {
// Initialise these classes when Tomcat starts
"jreLeakListener.jarUrlConnCacheFail"), e);
} catch (IOException e) {
log.error(sm.getString(
- "jreLeakListener.jarUrlConnCacheFail"), e);
+ "jreLeakListener.jarUrlConnCacheFail"), e);
+ }
+ }
+
+ /*
+ * Haven't got to the root of what is going on with this leak but if
+ * a web app is the first to make the calls below the web
+ * application class loader will be pinned in memory.
+ */
+ if (xmlParsingProtection) {
+ DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+ try {
+ factory.newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ log.error(sm.getString(
+ "jreLeakListener.xmlParseFail"), e);
}
}
}
interceptorValve.alreadyStarted=InterceptorValve has already been started
interceptorValve.notStarted=InterceptorValve has not yet been started
jreLeakListener.jarUrlConnCacheFail=Failed to disable Jar URL connection caching by default
+jreLeakListener.xmlParseFail=Error whilst attempting to prevent memory leaks during XML parsing
naming.wsdlFailed=Failed to find wsdl file: {0}
naming.bindFailed=Failed to bind object: {0}
naming.jmxRegistrationFailed=Failed to register in JMX: {0}
case by case basis as required. Defaults to <code>true</code>.</p>
</attribute>
+ <attribute name="xmlParsingProtection" required="false">
+ <p>Enables protection so that parsing XML files within a web application
+ does not result in a memopry leak. Note that memory profilers may not
+ display the GC root associated with this leak making it particularly
+ hard to diagnose. Defaults to <code>true</code>.</p>
+ </attribute>
+
</attributes>
</subsection>