Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
  • !! This page is under construction !!*

For some time Tomcat has had some means of protection against memory leaks when stopping or redeploying applications. This page tries to list them, and shows the situations where leaks can be detected and fixed.

...

Leak cause

Detected by tomcat

Fixed by tomcat

Possible enhancements

Custom ThreadLocal class

>=6.0.24

6.0.24-6.0.26 but is unsafe. Made optional from 6.0.27

Detect child classloaders, BZ 49159

Webapp class instance as ThreadLocal value

>=6.0.24

6.0.24-6.0.26 but is unsafe. Made optional from 6.0.27

Detect child classloaders, BZ 49159

Webapp class instance indirectly held through a ThreadLocal value

no

no

Renew threads in the worker pool

ThreadLocal pseudo-leak

>=6.0.24

6.0.24-6.0.26 but is unsafe. Made optional from 6.0.27

BZ 49159

ContextClassLoader / Threads spawned by webapps

>=6.0.24

In 6.0.24-6.0.26 TimerThread are stopped but it may lead to problems. Optional from 6.0.27 with the clearReferencesStopTimerThreads flag. Other threads may be stopped with the clearReferencesStopThreads flag, but it's unsafe.

Detect child classloaders, Fix the application to stop the thread when the application is stopped

ContextClassLoader / Threads spawned by classes loaded by the common classloader

>=6.0.24

In 6.0.24-6.0.26 TimerThread are stopped but it may lead to problems. Optional from 6.0.27 with the clearReferencesStopTimerThreads flag. Other threads may be stopped with the clearReferencesStopThreads flag, but it's unsafe.

Detect child classloaders, fix the offending code (set the correct CCL when spawning the thread)

ContextClassLoader / Threads spawned by JRE classes

no

>=6.0.24 pre-spawns some known offenders

 

static class variables

no

> 6.0.? . Disabled by default with tomcat 7

 

LogFactory

 

> 6.0.?

 

JDBC driver registration

> 6.0.?

> 6.0.?

 

RMI Target

 

> 6.0.?

 

...

  • Anchor
    48837
    48837
    48837 - Memory leaks protection does not cure leaks triggered by JSP pages code Anchor488954889548895 - WebAppClassLoader.clearThreadLocalMap() concurrency issues Anchor489714897148971 - memory leak protection : stopping TimerThreads should be optional and disabled by default
  • Anchor
    49159
    49159
    49159 - Improve ThreadLocal memory leak clean-up
  • Sun bug 4957990 - In some cases the Server JVM fails to collect classloaders. According to this page it should have been fixed with java 6u16 but actually it was not. It seems to be fixed with 6u21 (documented here and verified by the author of this wiki page).

...