Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7143

groovy.json.DateFormatThreadLocal creates a memory leak

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.7
    • 2.4.0-beta-4
    • None
    • None

    Description

      A warning is created by Tomcat's memory leak protection:

      30-Sep-2014 09:38:15.637 SEVERE [http-nio-9280-exec-162] org.apache.catalina.loader.WebappClassLoader.checkThreadLocalMapForLeaks The web application [/webapp] created a ThreadLocal with key of type [groovy.json.DateFormatThreadLocal] (value [groovy.json.DateFormatThreadLocal@5cc37e3c]) and a value of type [java.text.SimpleDateFormat] (value [java.text.SimpleDateFormat@faabb360]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      

      These problem usually occur when you subclass ThreadLocal (usually to implement initialValue). Those classes reference the webapp's classloader. The ThreadLocal subclass in turn is referenced by each Thread instance (that's how ThreadLocals are implemented, they have a "helper-Map" in each Thread instance, so the leak is actually not a tiny Random instance but the whole webapp's classloader with a bunch of class definitions and statically referenced parts of the webapp.
      If you don't subclass ThreadLocal and set the value lazily instead, the problem should be solved.

      Attachments

        Activity

          People

            pschumacher Pascal Schumacher
            jkemnade Jochen Kemnade
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: