4 Replies Latest reply on Mar 15, 2006 5:09 PM by knifegun

    memory leaks in redeployment

    ramana Newbie

      I did debug my application with JProfiler Memory Debugger.
      With no doubt I found some memory leaks on every redeployment.

      My environement: JBoss 4.0.4RC1 using EJB3 session beans,Java 5.

      some issues:
      1. We have got some singleton classes in our application. Our application is deployed as ear containing all dependent jars with in ear (uses isolated classloading). After debugging with MemoryDebugger I came to figure out that all old stateless beans still exists and also all singleton classes exists. Memory increses by 20MB on every redeployment (This may be still increases,if my application uses more memory),ofcourse which causes OutOfMemory after some redeployments.

      2. One of our third-party library uses ThreadLocal inside their application implementation, which one of my singleton class holds this. As ofcourse my singleton never garbaged and so forth. Is this ThreadLocal somehow causing JBoss from invoking garbage collection.

      3. I am not sure, but I found one instanceof ThreadGroup (JBoss) is holding all stateless beans instances. Same ThreadGroup instance is used even after redeployment. So old stateless beans are garbaged as ThreadGroup is not garbaged.

      Please help me.What can be the reasons for memory leaks in my application.

      Thanks in advance,
      Thanks in advance,

        • 1. Re: memory leaks in redeployment
          ramana Newbie

          I am sorry. In 3. I mean to say- " So old stateless beans are NOT garbaged as ThreadGroup is not garbaged. "

          Also I found another scenario,
          JBoss ServerThread class is also holding all ThreadLocal instances.
          Is this a known bug?


          • 2. Re: memory leaks in redeployment
            Bill Burke Master

            JBoss doesn't invoke garbage collection, this is the job of the VM.

            Stateless beans instances are pooled in a threadlocal variable stored in the EJBContainer. The EJBContainer should be undeployed and thus garbage collected and thus the ThreadLocal should be garbage collected as well. Are you seeing EJBContainer instances leaked?

            Can you narrow this down to a really small reproducable test case?

            • 3. Re: memory leaks in redeployment
              ramana Newbie

              I did force n number of times manual garbage collection while taking memory snapshot.But no luck. I am sure that those instances get never released.

              From your input, I tried to look at EJB3/EJB instances leakage. Thanks god they are not leaked. It seems there is something to do with ThreadLocal or ServerThread instance.

              Just as a quick test, I opened some file handles within POJO singleton class implementation,which internally used by one of my ejb3 slsb. In finalize() of singleton class I close these filehandles.

              I tried redeploying my app n number of times,singleton instance is created n times(ofcourse) , but as no singleton is garbaged, all file handles are still kept opened (Used a ProcessExplorer tool in windows) ofcourse which leads to memory leak.

              I will try providing you a testcase.

              Till that time, here is referrer details:

              <h3>Instance Detail</h3>
              <h4>Referrer Tree</h4>
              TestEJB3 1480368

              StatelessBeanContext 1480412 (bean)

              ThreadLocal$ThreadLocalMap$Entry 1482804 (value)

              ThreadLocal$ThreadLocalMap$Entry [512] 1293433 ([151])

              ThreadLocal$ThreadLocalMap 1281230 (table)

              ServerThread 741958 (threadLocals)

              LinkedList$Entry 819620 (element)
              WeakHashMap$Entry 777095 (referent)
              Thread [32] 775226 ([20])
              Java Frame 1152921504606846993
              Java Frame 1152921504606846990
              Java Frame 1152921504606846989


              • 4. Re: memory leaks in redeployment
                knifegun Newbie

                Any updates on this issue? We are using EJB3 with Lazy fetch and we have noticed memory leaks even when JBoss is restarted.