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