1 Reply Latest reply on Dec 4, 2007 12:16 PM by Jim Slattery

    Possible Memory Leak? (1.4 SP7)

    Jim Slattery Newbie

      Hi all,
      I'm running a test program with a simple loop that writes an object to the cache and then removes it.
      As I monitor with JConsole, the heap usage grows and grows and can't be reclaimed with a garbage collection. Eventually it crashes with an OutOfMemoryError.

      Below is my code.

      package test;
      import static java.lang.System.out;
      import org.jboss.cache.PropertyConfigurator;
      import org.jboss.cache.aop.PojoCache;
      public class MemoryLeakTest {
       static PojoCache cache;
       public static void cacheInit() throws Exception {
       cache = new PojoCache();
       PropertyConfigurator config = new PropertyConfigurator();
       config.configure(cache, "replSync-service.xml");
       public static void main(String[] args) throws Exception {
       final int MAX = 1000000;
       final int INNER_MAX = 2;
       final int DEPTH = 0;
       out.println("Adding to cache...");
       for (Integer i=0; i<MAX; i++) {
       String fqn = "/" + i;
       if (i % 100 == 0) out.println(" putting at: " + fqn);
       for (int j=0; j<INNER_MAX; j++) {
       cache.putObject(fqn+"/"+j, new DummyObject(DEPTH));
       for (int j=0; j<INNER_MAX; j++) {
       public static void cacheStop() {

      package test;
      import java.util.ArrayList;
      import java.util.List;
      import java.util.Random;
      public class DummyObject {
       static Random random = new Random();
       byte[] data;
       List<DummyObject> children = new ArrayList<DummyObject>();
       public DummyObject(int depth) {
       this.data = new byte[100];
       if (depth > 0) {
       int nextDepth = depth - 1;
       children.add(new DummyObject(nextDepth));
       children.add(new DummyObject(nextDepth));
       private String generateRandomData() {
       StringBuilder sb = new StringBuilder();
       for (int i=0; i<1000; i++)
       return sb.toString();


      <?xml version="1.0" encoding="UTF-8"?>
       <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/>
       <mbean code="org.jboss.cache.TreeCache" name="jboss.cache:service=TreeCache">
       <attribute name="TransactionManagerLookupClass">org.jboss.cache.DummyTransactionManagerLookup</attribute>
       <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
       <attribute name="CacheMode">REPL_SYNC</attribute>
       <attribute name="UseReplQueue">false</attribute>
       <attribute name="ReplQueueInterval">0</attribute>
       <attribute name="ReplQueueMaxElements">0</attribute>
       <attribute name="ClusterName">TreeCache-Cluster</attribute>
       <attribute name="ClusterConfig">
       <UDP mcast_addr="" mcast_port="58866"
       ip_ttl="64" ip_mcast="true"
       mcast_send_buf_size="150000" mcast_recv_buf_size="80000"
       ucast_send_buf_size="150000" ucast_recv_buf_size="80000"
       <PING timeout="2000" num_initial_members="3"
       up_thread="false" down_thread="false"/>
       <MERGE2 min_interval="10000" max_interval="20000"/>
       <VERIFY_SUSPECT timeout="1500"
       up_thread="false" down_thread="false"/>
       <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"
       max_xmit_size="8192" up_thread="false" down_thread="false"/>
       <UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10"
       <pbcast.STABLE desired_avg_gossip="20000"
       up_thread="false" down_thread="false"/>
       <FRAG frag_size="8192"
       down_thread="false" up_thread="false"/>
       <pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
       shun="true" print_local_addr="true"/>
       <pbcast.STATE_TRANSFER up_thread="true" down_thread="true"/>
       <attribute name="FetchInMemoryState">true</attribute>
       <attribute name="InitialStateRetrievalTimeout">15000</attribute>
       <attribute name="SyncReplTimeout">15000</attribute>
       <attribute name="LockAcquisitionTimeout">10000</attribute>
       <attribute name="EvictionPolicyClass"></attribute>
       <attribute name="UseRegionBasedMarshalling">true</attribute>

      jboss-aop.xml contains:
      <?xml version="1.0" encoding="UTF-8"?>
       <prepare expr="field(* test.DummyObject->*)" />

      I launch MemoryLeakTest with these VM parameters:
      -Dcom.sun.management.jmxremote -javaagent:.\lib\jboss-aop-jdk50.jar -Djboss.aop.path=.\resources\pojocache-aop.xml -Djboss.aop.path=.\resources\jboss-aop.xml -Xms128M -Xmx128M

      Is there anything obvious I might be doing wrong here?


        • 1. Re: Possible Memory Leak? (1.4 SP7)
          Jim Slattery Newbie

          Looks like this could be "user error".

          In the above code, it looks like objects are getting added to cache locations "/i/j".

          While each objects is removed from "/i/j", the "/i" node remains (leaked by the user). I added an additional statement:


          That seems to clean it up, and the code can execute forever without leaking memory.

          However, I briefly tried doing this in JBossCache 2.0 (using attach()/detach() instead of putObject()/remove()), and it appears that the heap-usage still grows rapidly, even though it looks like all the cache nodes are getting removed.

          I think we'll be using 1.4, so I won't investigate it further. Thanks to those who took a look at this.