2 Replies Latest reply on Jan 22, 2005 12:33 PM by aloubyansky

    Memory Leak: Read-Only Method

    tripperm

      While upgrading our application from JBoss 3.0.2 to JBoss 3.2.5 we began experiencing a memory leak. Using JProfiler we found that there was a growing number of references to one of our entity beans that were never being released. I wrote a very simple unit test which performed the following steps:

      1) Look up the home interface of the entity bean
      2) Callled the findByPrimaryKey() method.
      3) Called a getModel() method on the entity bean which returned a value object with the bean?s data back to the caller.

      The entity bean had no relationships defined to other beans, and the test was not executed in a transaction.

      I then ran the unit test in an infinite loop, always looking up the same entity bean each time, and after about 20 minutes (50,000 iterations) the JVM ran out of memory. JProfiler showed that there were over 50,000 references to the one entity bean in memory.

      I then noticed that the getModel() method was declared as read-only in the descriptor file. I removed this and then re-ran my test. The JVM never ran out of memory and there was only 1 reference to the problematic bean in memory. Once we then removed all of the read-only declarations from our descriptor files, our memory leak problem was resolved.

      Here is our setup:
      Java 1.4.2_03
      Jboss 3.2.5 on Windows XP Professional
      Using CMP 2.0 with commit option C
      Bean caching is set to a maximum of 1000 (instead of the 1000000 by default)

      I wasn?t able to find any other similar problems reported in the forums, and thought I would post this to help anyone else who may be experiencing similar issues.

      Tripper McCarthy