1. Axis
  2. AXIS-935

Using ThreadLocal Call objects in a servlet memory leak both on client and server side


    • Type: Bug Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: 1.1rc2
    • Fix Version/s: None
    • Component/s: Basic Architecture
    • Labels:
    • Environment:
      Operating System: All
      Platform: All


      I discovered using Axis in tomcat causes a memory leak.

      It seems using threadlocal in the classes causes a memory leak for each Call
      that is created. Threadlocal sticks around until the calling thread dies, and
      since tomcat keeps threads alive to answer new calls, the threadlocal data
      never goes away. The Call object gets stuck in the threadlocal data, which
      contains the entire soap response and all objects. This is a BIG memory leak.
      I initially cleared it by forcing all Call objects to clean their member vars
      after I was done with a call, then I realized the source was from the thread
      local class. Here is some info I found about threadlocal:

      This is stated in the Sun Javadocs for ThreadLocal:

      Each thread holds an implicit reference to its copy of a
      ThreadLocal as long as the thread is alive and the
      ThreadLocal object is accessible; after a thread goes
      away, all of its copies of ThreadLocal variables are
      subject to garbage collection (unless other references
      to these copies exist).

      So, this means that ANY APPLICATION that uses PreparedStatements in a thread
      that 1) either does a lot of PreparedStatements or 2) never dies (i.e., a
      main thread) will ALWAYS eventually have an out of memory error. Simply put,
      this is a MEMORY LEAK. I imagine that the leak is very small, the
      ThreadLocal object only contains one member variable, maybe 64 bytes or less
      (depending on the VM implementation). So, our 60,000 PreparedStatements of 2
      ThreadLocals each times 64 bytes (my wild guess) is 7.5MB.

      Ideas? I've never used threadlocal myself so this is new to me.

        Issue Links


          Jennifer Jackson created issue -
          Serge Knystautas made changes -
          Field Original Value New Value
          issue.field.bugzillaimportkey 21186 14876
          Davanum Srinivas made changes -
          Assignee Axis Developers Mailing List [ ]
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Resolved [ 5 ]
          Davanum Srinivas made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Davanum Srinivas made changes -
          Status Reopened [ 4 ] Closed [ 6 ]
          Resolution Fixed [ 1 ]
          Tom Jordahl made changes -
          Resolution Fixed [ 1 ]
          Status Closed [ 6 ] Reopened [ 4 ]
          Davanum Srinivas made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Mark Thomas made changes -
          Workflow jira [ 24871 ] Default workflow, editable Closed status [ 12555566 ]
          Mark Thomas made changes -
          Workflow Default workflow, editable Closed status [ 12555566 ] jira [ 12578917 ]
          Andreas Veithen made changes -
          Link This issue relates to AXIS-2850 [ AXIS-2850 ]


            • Assignee:
              Jennifer Jackson
            • Votes:
              2 Vote for this issue
              2 Start watching this issue


              • Created: