3 Replies Latest reply on Mar 14, 2007 2:43 PM by Brian Stansberry

    Memory leak when using JbossCache and JOTM

    arjan tijms Novice

      Hi,

      When using JbossCache in Tomcat 5.5 with JOTM as the JTA transaction manager, I stumbled upon a memory leak. After investigating with a profiler I noticed that an object I removed from JbossCache kept being referenced by a org.jboss.cache.marshall.JBCMethodCall, which was via among others a org.jboss.cache.TransactionEntry being referenced by a org.objectweb.jotm.SubCoordinator.

      I'm using JBossCache in the typical way:

      TreeCache treeCache = new TreeCache();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(treeCache, "META-INF/treecache.xml");
      treeCache.startService();
      
      UserTransaction tx = (UserTransaction) new GenericTransactionManagerLookup().getTransactionManager();
      
      tx.begin();
      
      treeCache.put( "/test" , "foo", someTestObject );
      
      tx.commit();
      
      treeCache.removeData( "/test" ); // extra, for test
      treeCache.remove( "/test" );
      
      treeCache.stopService();
      treeCache.destroyService();
      


      After executing this code, "someTestObject" remains in memory.

      Is this a known problem? Could it be a bug in JOTM or is the problem with JBossCache?

        • 1. Re: Memory leak when using JbossCache and JOTM
          Brian Stansberry Master

          Does the reference chain from the JOTM object lead through a javax.transaction.Synchronization implementation? For example, org.jboss.cache.interceptors.TxInterceptor$RemoteSynchronizationHandler (or TxInterceptor$LocalSynchronizationHandler)?

          If not, please post the full reference chain.

          If so, two possibilites:

          1) JOTM is holding onto the ref to the Synchronization for a little while, but will eventually clean it up and your object will be gc'd.

          2) JOTM is holding a ref to the Synchronization and won't ever release it. That would be a bug in JOTM.

          See http://www.jboss.com/index.html?module=bb&op=viewforum&f=164 for a question I raised with our transaction gurus that deals with a strategy we could employ to aggressively cut the reference chain.

          • 2. Re: Memory leak when using JbossCache and JOTM
            arjan tijms Novice

             

            "bstansberry@jboss.com" wrote:
            Does the reference chain from the JOTM object lead through a javax.transaction.Synchronization implementation? For example, org.jboss.cache.interceptors.TxInterceptor$RemoteSynchronizationHandler (or TxInterceptor$LocalSynchronizationHandler)?


            Yes it does. Just for clarity I'll post the whole reference chain anyway:

            [sticky class] (jprofiler term.)
            |
            class com.sun.corba.se.impl.util.Utility
            |
            com.sun.corba.se.impl.util.IdentityHashtable
            |
            <class>[]
            |
            com.sun.corba.se.impl.util.IdentityHashTableEntry
            |
            org.objectweb.jotm.SubCoordinator
            |
            java.util.Vector
            |
            <class>[]
            |
            org.jboss.cache.interceptors.OrderedSynchronisationHandler
            |
            ...
            |
            org.jboss.cache.interceptors.TxInterceptor$LocalSynchronizationHandler
            |
            org.jboss.cache.TransactionEntry
            |
            ...
            |
            org.jboss.cache.marshall.JBCMethodCall
            |
            <class>[]
            |
            [the object I put into JBossCache]
            




            2) JOTM is holding a ref to the Synchronization and won't ever release it. That would be a bug in JOTM.


            This is what is currently happening, as I don't think "for a little while" means atleast a few hours ;)

            I'm going to read the link you posted. Meanwhile I'm also reading through JOTM's sourcecode to see if it's anything trivial to fix (but I'm afraid it isn't).


            • 3. Re: Memory leak when using JbossCache and JOTM
              Brian Stansberry Master

              See http://jira.jboss.com/jira/browse/JBCACHE-1007 for a JIRA that will break the reference chain from the Synchronization back to your object.

              If JOTM is not fixable, it should be fairly straightforward for you to patch your JBoss Cache instance.