[rules-users] WorkingMemoryLogger + statelessSessions = memory leak?

Swindells, Thomas TSwindells at nds.com
Tue Oct 25 12:30:26 EDT 2011


Anybody?

From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Swindells, Thomas
Sent: 21 October 2011 14:49
To: Rules Users List (rules-users at lists.jboss.org)
Subject: [rules-users] WorkingMemoryLogger + statelessSessions = memory leak?

Hi everyone,

I believe that there is a memory leak when using WorkingMemoryLoggers with statelessSessions. This was raised against 5.1.1 but I think it will still exist in the latest as well.

Our code basically has the following pattern:

KnowledgeBase kb ==;

while(nextEvent()) {
                StatelessKnowledgeSession session = kb.newStatelessKnowledgeSession();
                auditor = new WorkingMemoryInMemoryLogger(session);
                session.execute(getEvent());
                dumpAuditLog(auditor);
                session = null; //no dispose it's stateless
}

We were getting Out of Memory Exception on site and the stack dump showed a high number of MemoryLoggers on the heap.

Having a look at the code I think the problem is in the WorkingMemoryLogger constructor:
} else if (session instanceof StatelessKnowledgeSessionImpl) {
                                ((StatelessKnowledgeSessionImpl) session).workingMemoryEventSupport.addEventListener( this );
                                ((StatelessKnowledgeSessionImpl) session).agendaEventSupport.addEventListener( this );
                                ((StatelessKnowledgeSessionImpl) session).ruleFlowEventSupport.addEventListener( this );
                                ((StatelessKnowledgeSessionImpl) session).getRuleBase().addEventListener( this );
                }

The last statement gets the knowledge base and attaches the event listener to it.
As far as I can see there is no way to dispose of the WorkingMemoryLogger and you don't dispose stateless sessions (and it doesn't know about the listener anyway). This means that even after the session is gone the rule base still has a reference to the logger.

The work around is to make the logger a singleton and clear it in each loop rather than creating a new one each time, however this obviously doesn't scale to multiple threads.

Have I missed some fundamental in the api or should I raise a Jira for this?

Thomas

________________________________

**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com<mailto:postmaster at nds.com> and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111025/e3f11c78/attachment.html 


More information about the rules-users mailing list