I’m in the middle of trying to upgrade our application to Drools 5.2 from 5.1 however I keep facing out of memory issues (I’ve also tried on the current 5.3 beta).

I’ve simplified my code into the following test case which on my machine after about 600 or so iterations gives an Out of memory exception:

 

@Test

       public void testCase() throws InterruptedException

       {

              KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

              KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();

              kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

                           

              for(int i = 0; i < 1000; i++) {

                     System.out.println("Run " + i);

                     StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();

                     for(int j = 0; j < 100; j++) {

                           session.insert(new byte[10240]);

                     }

                    

                     session.dispose();

                     session = null;

                     System.gc();

              }     

       }

 

Am I missing anything here – I’m calling session.dispose() which is all I believe is necessary when finishing the session, however using a profiler shows that all the StatefulKnowledgeSessionImpl and ReteooStatefulSessions are still present and therefore keeping hold of all the byte arrays and memory.

 

Using a profiler it shows that the GC roots of the StatefulKnowledgeSessionImpl are

kruntime of org.jbpm.process.instance.ProcessRuntimeImpl

kruntime of org.jbpm.process.instance.event.DefaultSignalManager

kruntime of org.jbpm.process.instance.timer.TimerManager

kruntime of org.drools.reteoo.ReteooStatefulSession

 

Similarly for the ReteooStatefulSession:

session of org.drools.impl.StatefulKnowledgeSessionImpl

session of org.drools.impl.StatefulKnowledgeSessionImpl

workingMemory of org.jbpm.process.instance.ProcessRuntimeImpl

workingMemory of org.jbpm.process.instance.ProcessRuntimeImpl

workingMemory of org.jbpm.process.instance.ProcessRuntimeImpl

 

Is this a known issue? Am I missing anything in my code above.

I guess the alternative is to reuse my sessions – what is the most efficient way to remove all the facts from the working memory and get it back into a pristine state?

 

Thanks,

 

Thomas




**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster@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
**************************************************************************************