4 Replies Latest reply on Mar 5, 2007 4:30 AM by gmeroz

    memory leak

      I use JBossCache-all-2.0.0.ALPHA2.

      i have a memory leak in my application when i use JBossCache. The following test reproduce it. It add 100 Person object to the cache, than it remove them from the cache & and repeat...

      When i use profiler, I see that the number of instances of Person is raising. (even if i force GC).

      public void testMemoryLeak(){
       PojoCache cache = PojoCacheFactory.createCache("com/bevents/infra/service/cache/cache.xml", true);
       String category = "testCat";
       while (true) {
       for (int i=0 ;i<100; i++) {
       Person person = new Person();
       person.setName("aaa");
       cache.attach(category+"/testPerson"+i,person);
       assertEquals(person,cache.find(category+"/testPerson"+i));
       }
       // delete from the cache.
       cache.getCache().getRoot().removeChild(Fqn.fromString(category));
       assertNull(cache.find(category+"/testPerson0"));
       System.out.println("sleep");
       try {
       Thread.sleep(5000);
       } catch (InterruptedException e) {
       e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
       }
       }
       }
      


      this is the configuration XML loaded for the cache:
      <?xml version="1.0" encoding="UTF-8"?>
      <server>
       <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/>
       <mbean code="org.jboss.cache.TreeCache"
       name="jboss.cache:service=TreeCache">
      
       <depends>jboss:service=Naming</depends>
       <depends>jboss:service=TransactionManager</depends>
      
       <attribute name="TransactionManagerLookupClass">org.jboss.cache.DummyTransactionManagerLookup</attribute>
       <attribute name="IsolationLevel">READ_COMMITTED</attribute>
      
       <attribute name="CacheMode">LOCAL</attribute>
       </mbean>
      
      
      
      </server>
      


        • 1. Re: memory leak
          manik

          Thanks for this, will investigate.

          • 2. Re: memory leak
            manik
            • 3. Re: memory leak
              jason.greene

              This is a usage problem. PojoCache creates internal nodes in /__JBossInternal__ which aren't cleared since PojoCache is bypassed for the bulk delete operation. So basically any object that has attach() called on it, can only be removed via the PojoCache detach method.

              Also, the structure __JBossInternal__ is not considered public so you should not attempt to modify it yourself.

              So the only way to do a bulk delete operation at the moment, is to iterate over all of the ids and call detach() on each one. Feel free to create a feature request if this is not sufficient.

              -Jason

              • 4. Re: memory leak

                I think there should be a way to clear an entire area in the cache (as a bulk). Finding all the POJOs in the cache and deleting them one by one, sound expensive.