logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gülcü <c...@qos.ch>
Subject RE: web app using log4j not garbage collected when shutdown with tomcat manager app
Date Wed, 22 Sep 2004 13:10:09 GMT
At 02:45 PM 9/22/2004, you wrote:
>Ceki,
>
>I think I've found a workaround for this problem.
>
>Debugging the log4j property configuration code when executing test case 
>3, I noticed it used the java.beans package in PropertySetter to set the 
>ConversionPattern property of the appender layout object.  This code 
>doesn't get executed in the other testcases because no Layout parameters 
>(including ConversionPattern) are specified (at least not specified via 
>the configuration file).
>
>After googling a bit on "Inspector", "memory", "leak" I found a few clues 
>that led to the inspection of the java.beans.Introspector class.  This 
>class includes the following comment in its javadoc:
>
>  * Because the Introspector caches BeanInfo classes for better performance,
>  * take care if you use it in an application that uses
>  * multiple class loaders.
>  * In general, when you destroy a <code>ClassLoader</code>
>  * that has been used to introspect classes,
>  * you should use the
>  * {@link #flushCaches <code>Introspector.flushCaches</code>}
>  * or
>  * {@link #flushFromCaches <code>Introspector.flushFromCaches</code>} method
>  * to flush all of the introspected classes out of the cache.
>
>I then added a call to Introspector.flushCaches() in 
>SimpleServlet.destroy() after the call to LogManager.shutdown().  With 
>this additional line of code, test case 3 is now successful - the web app 
>classes and the tomcat web app class loader are now garbage collected.
>
>
>Does this seem like a reasonable explanation/solution?  This doesn't 
>appear to be a log4j issue (I hope I didn't cause anyone any extra 
>work).  I would guess that maybe Tomcat should call 
>Introspector.flushCaches() when it shuts down a web app since it's 
>throwing away the classloader for the web app.  For now, I'll include this 
>line of code during web app shutdown.

This makes perfect sense. Due to the presence of the ConversionPattern 
property, Test 3 is the only time PropertyConfigurator will use 
introspection, hence the failure in garbage collection of the web-app.

Good call!

>Hope this helps,

It sure does.

>-Jay

-- 
Ceki Gülcü

      For log4j documentation consider "The complete log4j manual"
      ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp  



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message