Our application had to survive a night with full load. On the next morning the heap was full of JbpmContext's.
After looking at the source code of Seam and at the debug messages we came up with this hypothesis:
- The SFSB EjbSynchronizations is placed in the event context, the Seam-JbpmContext-Component also lives in the event context.
- Using EJB transactions, EjbSynchronizations is responsible for cleaning up the JbpmContext after the end of the transaction.
- Unfortunately the event context ends BEFORE EjbSynchronizations has the chance to clean up the JbpmContext.
Using BMT the transaction ends before the event context ends. Thus, the JbpmContext is cleaned up.
We switch all our MDBs, EJB-timers, and Web-services from CMT to BMT and (after fixing some other leaks, e.g. a class loader issue in jBpm), we survived the night.
I wrote a small test application that shows the memory leak and I will try to attach it to this issue.
It is a Maven application that consists of
- a Web-GUI to start the test and displays the results (http://localhost:8080/leak/)
- a SFSB that sends 10 messages each to two queues (the standard queues A and B), waits a little bit, and does a gc
- two MDBs, one with CMT, one with BMT, which uses Seam injection to access a jBpm-Context
- an application scoped POJO that saves the contexts in a Set using a weak reference
After executing the tests and the GC, the surviving references are displayed. You can see that the CMT references are not gs'ed whereas the BMT references are cleaned up. You can execute the test several times.