[rules-users] EventFactHandle retained in memory after FactCount reaches 0 for temporal-based rule

Kent Anderson kent.anderson at psware.com
Thu Jul 10 18:54:56 EDT 2014


Correction:  The original post did not include another rule that exists in the stream.  The memory leak does not appear unless both rules are active in the stream.

declare MyEvent 
  @role(event) 
  @timestamp(timestamp) 
end 

/* If a RAISE is buffered for N seconds, send it out */
rule "forward raise"
	no-loop
	duration (3s)
when
	$raise : MyEvent(eventState == EventState.RAISE, $raiseId : eventId)
then
	System.out.println("Forwarding RAISE(" + $raiseId + ")");
	delete($raise);
end

/* When CLEAR, and buffered, clear them both out */
rule "forget it ever happened"
	no-loop
when
	$clear : MyEvent(eventState == EventState.CLEAR, $clearId : eventId)
	$raise : MyEvent(eventState == EventState.RAISE, eventId == $clearId)
then
	System.out.println("Forgetting RAISE/CLEAR(" + $clearId + ")");
	delete($clear);
	delete($raise);
end


On Jul 10, 2014, at 2:50 PM, Kent Anderson <kent.anderson at psware.com> wrote:

> The following rule produces a memory leak in Drools 6.1.0-SNAPSHOT:
> 
> (Stream mode)
> 
> declare MyEvent 
>   @role(event) 
>   @timestamp(timestamp) 
> end 
> 
> /* If a RAISE is buffered for N seconds, send it out */
> rule "forward raise"
> 	no-loop
> 	duration (3s)
> when
> 	$raise : MyEvent(eventState == EventState.RAISE, $raiseId : eventId)
> then
> 	System.out.println("Forwarding RAISE(" + $raiseId + ")");
> 	delete($raise);
> end
> 
> 
> I see the rule fire as expected, printing out the message 3 seconds after the event is added into the session.  While the event is waiting, I see a FactCount of 1 in the session.  After the rule fires, the fact count goes to 0.  However, using JVisualVm, querying the heap dump shows 1 instance of MyEvent, referenced by an EventFactHandle and several other Drools objects.
> 
> Is this a bug, or is there a better way to write this rule so Drools’ internals let go of the object after it is no longer a fact?
> 
> <PastedGraphic-1.png>
> 
> <PastedGraphic-2.png>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20140710/910f3c87/attachment.html 


More information about the rules-users mailing list