On 19/07/2016 17:19, Berneburg, Cris J. - US wrote:

<snip/>

>> This is probably a useful read:
>> http://people.apache.org/~markt/presentations/2010-11-04-Memory-Leaks-60mins.pdf
>>
>> Despite the age, it is still very relevant today.
> 
> 
> Thanks for reminding me about that document.  It does sound relevant.  The 
> document says,
> 
>> How memory leaks occur: Reference chains
>> [...]
>> Retaining a reference to a single object from a web application
>> pins every class loaded by the web application in the Permanent
>> Generation
> 
> Practically speaking, how is a reference retained?
> 1. Is a module-level (member) variable in a Servlet an example?

No. Assuming the class that defines the Servlet is packaged with the web
application (i.e. in a JAR in WEB-INF/lib or in WEB-INF/classes

> 2. How about using ServletContext.setAttribute without an accompanying 
> removeAttribute?

No.

> 3. I see in one of my listeners some member (module-level) variables: a 
> private static for the logger and also a protected final String.  Is that a 
> problem?

No.

> If you could provide a little more guidance about the details, I would 
> appreciate it.

Sure.

There are two categories of objects we are concerned about. Objects
defined by classes that are provided by your web application (in
WEB-INF/lib or WEB-INF/classes) and objects defined by classes that are
provided by the container (Tomcat) or the JVM.

References from web application objects to web application objects are fine.

References from web application objects to container objects are fine.

References from container objects to web application objects are
potentially a problem.

Additionally, references from container objects to the web application
class loader are potentially a problem.

For example:

When you start a thread in a web application, the thread context class
loader will be the web application class loader and the thread holds a
reference to this. If the thread is not stopped when the web application
is stopped there will be a reference held to the web application class
loader which will cause a leak.

If you add a logging framework to Tomcat's lib directory and then
package a custom log formatter with your web application, the formatter
will be registered with the logging framework and unless you unregister
it when the application stops there will be reference from logging
framework to custom formatter object to custom formatter class to web
application class loader which will cause a leak.

HTH,

Mark

P.S. I'll be talking about this (hopefully - if my talk gets accepted)
at ApacheCon EU later this year.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to