<div><br></div>   Chris,<div><br></div><div>   I haven&#39;t tried your code, but just looking at the rule, there is no temporal correlation between DataReading and ReconfigEvent, so if I am not mistaken, that will create a required interval of infinite time when the temporal reasoning is applied, meaning the engine has to keep the readings in memory forever. </div>
<div><br></div><div>   Adding a temporal constraint on the ReconfigEvent pattern on your rule or defining an explicit expiration policy for the DataReadings are ways to work around that.</div><div><br></div><div>   Edson<br>
<br><div class="gmail_quote">2011/7/26 Chris Richmond <span dir="ltr">&lt;<a href="mailto:crichmond@referentia.com">crichmond@referentia.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello<br>
<br>
I am performing a simple test of injecting an event every 1 millisecond<br>
like so:<br>
<br>
       for (int x = 0; x &lt; 100000; x++){<br>
         DataReading dr = new DataReading(&quot;Reading &quot; + x, 12.0f);<br>
         myStream.insert(dr);<br>
         ksession.fireAllRules();<br>
         Thread.sleep(1);<br>
<br>
       }<br>
<br>
<br>
The rule that evaluates this is simple.  It basically delays &quot;then&quot; for<br>
3s to see if a followup reading is inserted and makes sure that no<br>
ReconfigEvent is active(5s expiration).<br>
<br>
So if a reading comes in and a followup reading is not inserted within 3<br>
seconds and there is is not an existing ReconfigEvent event alive, then<br>
it should output and insert a ReconfigEvent, essentially disabling any<br>
DataReading action on those events for the next 5 seconds or so.  This<br>
all works just fine as expected.<br>
<br>
My question is, how come I don&#39;t get memory back when all 100,000 of my<br>
events have been inserted.  Memory goes up slowly over the course of<br>
insertions, which I can understand, but once that loop is finished,<br>
memory never reduces, so essentially, the application will eventually<br>
run out of memory after some time.   I should not have to explicitly<br>
remove/retract events should I? Shouldn&#39;t they be removed from working<br>
memory as soon as they are no longer viable?  What should I be doing to<br>
reclaim memory from the session/knowledgebase?<br>
<br>
I have included the full Main program here and the Sample.drl file below it.<br>
<br>
************FusionMain.java*****************<br>
<br>
package com.sample;<br>
<br>
import org.drools.KnowledgeBase;<br>
import org.drools.KnowledgeBaseConfiguration;<br>
import org.drools.KnowledgeBaseFactory;<br>
import org.drools.builder.KnowledgeBuilder;<br>
import org.drools.builder.KnowledgeBuilderError;<br>
import org.drools.builder.KnowledgeBuilderErrors;<br>
import org.drools.builder.KnowledgeBuilderFactory;<br>
import org.drools.builder.ResourceType;<br>
import org.drools.conf.EventProcessingOption;<br>
import org.drools.io.ResourceFactory;<br>
import org.drools.logger.KnowledgeRuntimeLogger;<br>
import org.drools.logger.KnowledgeRuntimeLoggerFactory;<br>
import org.drools.runtime.KnowledgeSessionConfiguration;<br>
import org.drools.runtime.StatefulKnowledgeSession;<br>
import org.drools.runtime.conf.ClockTypeOption;<br>
import org.drools.runtime.rule.WorkingMemoryEntryPoint;<br>
<br>
<br>
public class FusionMain {<br>
<br>
   @SuppressWarnings(&quot;restriction&quot;)<br>
   public static void main(String[] args) {<br>
<br>
<br>
     try {<br>
<br>
       KnowledgeSessionConfiguration config =<br>
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();<br>
       config.setOption( ClockTypeOption.get(&quot;realtime&quot;) );<br>
<br>
<br>
       KnowledgeBase kbase;<br>
       kbase = readKnowledgeBase();<br>
       StatefulKnowledgeSession ksession =<br>
kbase.newStatefulKnowledgeSession();<br>
<br>
       WorkingMemoryEntryPoint myStream =<br>
ksession.getWorkingMemoryEntryPoint(&quot;My Stream&quot;);<br>
<br>
       for (int x = 0; x &lt; 100000; x++){<br>
         DataReading dr = new DataReading(&quot;Reading &quot; + x, 12.0f);<br>
         myStream.insert(dr);<br>
         ksession.fireAllRules();<br>
         Thread.sleep(1);<br>
<br>
       }<br>
<br>
     } catch (Exception e) {<br>
       // TODO Auto-generated catch block<br>
       e.printStackTrace();<br>
     }<br>
<br>
   }<br>
<br>
   @SuppressWarnings(&quot;restriction&quot;)<br>
   private static KnowledgeBase readKnowledgeBase() throws Exception {<br>
     KnowledgeBuilder kbuilder =<br>
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
     kbuilder.add(ResourceFactory.newClassPathResource(&quot;Sample.drl&quot;),<br>
ResourceType.DRL);<br>
     KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
     if (errors.size() &gt; 0) {<br>
       for (KnowledgeBuilderError error: errors) {<br>
         System.err.println(error);<br>
       }<br>
       throw new IllegalArgumentException(&quot;Could not parse knowledge.&quot;);<br>
     }<br>
<br>
     KnowledgeBaseConfiguration kbConfig =<br>
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
     kbConfig.setOption( EventProcessingOption.STREAM );<br>
     KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbConfig);<br>
     kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
<br>
<br>
     return kbase;<br>
   }<br>
<br>
<br>
}<br>
<br>
<br>
*********Sample.drl*************************<br>
<br>
package com.sample<br>
<br>
<br>
import java.util.Date;<br>
<br>
declare DataReading<br>
     @role( event )<br>
end<br>
<br>
<br>
declare ReconfigEvent<br>
     @role( event )<br>
     @expires ( 5s )<br>
end<br>
<br>
<br>
<br>
rule &quot;Wait for follup reading or no config&quot;<br>
//lock-on-active<br>
when<br>
<br>
     $dr: DataReading(reading &gt; 10.0) from entry-point &quot;My Stream&quot;<br>
     not(DataReading(reading &lt; 10.0, this after[0s,3s] $dr) from<br>
entry-point &quot;My Stream&quot;)<br>
     not(ReconfigEvent() from entry-point &quot;My Stream&quot;)<br>
<br>
then<br>
     System.err.println(&quot;Action: &quot; + new Date(System.currentTimeMillis()));<br>
     System.err.println(&quot;Data reading &quot; + $dr.getName() + &quot; &gt; 10&quot;);<br>
     ReconfigEvent rce = new ReconfigEvent();<br>
     entryPoints[&quot;My Stream&quot;].insert( rce );<br>
<br>
end<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>
</div>