<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7650.28">
<TITLE>RE: Potential multi thread error and &quot;smal&quot; memory leak</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<BR>

<P><SPAN LANG="en-gb"><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Hi all,</FONT></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">for help you to understand the problem, I have make a small TestCase.</FONT></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">This memory leak is not &quot;infinity&quot;, the maximum size of this memory leak is &quot;~ size(WorkingMemory + Facts)&nbsp; x&nbsp; number rules on the rules base&quot;.</FONT></SPAN></P>
<BR>

<P><SPAN LANG="en-gb"><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Yves</FONT></SPAN>
</P>
<BR>

<P><SPAN LANG="en-gb"><FONT FACE="Arial" SIZE=2 COLOR="#000000"> &lt;&lt;MemoryLeakTest.zip&gt;&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT FACE="Arial Unicode MS">&gt;&nbsp;</FONT></SPAN><SPAN LANG="de-ch"></SPAN><SPAN LANG="de-ch"> <FONT SIZE=1 FACE="Tahoma">-----Message d'origine-----</FONT></SPAN>

<BR><SPAN LANG="de-ch"><B><FONT SIZE=1 FACE="Tahoma">&gt; De :&nbsp;</FONT></B> <FONT SIZE=1 FACE="Tahoma">Galante, Yves&nbsp; </FONT></SPAN>

<BR><SPAN LANG="de-ch"><B><FONT SIZE=1 FACE="Tahoma">&gt; Objet :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT></B> <FONT SIZE=1 FACE="Tahoma">Potential multi thread error and &quot;smal&quot; memory leak</FONT></SPAN>

<BR><SPAN LANG="de-ch"><FONT SIZE=1 FACE="Tahoma">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; Hi,</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; Class VariableContextEntry and ReturnValueContextEntry are </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; instantiated </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; when Package.addRule called.</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; This class are linked from &quot;Package rules&quot;.</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;Package =&gt; ... =&gt;&nbsp; VariableContextEntry</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; But class have a reference&nbsp; to the InternalWorkingMemory !</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;Package =&gt; ... =&gt; VariableContextEntry =&gt; Workingmemory&quot;</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; When this pseudo code is executed, at the end of the execution, </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; WorkingMemory need to be garbage collected, but it isn't </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; because she is </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; referenced by ReturnValueContextEntry and/or </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; VariableContextEntry, and </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; this class keeps an reference to the WorkingMemory.</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; I think this can be generate some error in multi thread and make an </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; &quot;smal&quot; memory leak.</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; It is right ?</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; The membre workingMemory can't be removed from </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; VariableContextEntry/ReturnValueContextEntry ?</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; ____________________</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; pseudo code (source : ReteooMannersTest)&nbsp; :</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; final Package ruleBase = new Package( &quot;org.drools.examples.manners&quot; );</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; ruleBase.addRule( getAssignFirstSeatRule() );</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; ...</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; SatefulSession session = ruleBase.newStatefulSession(false);</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; session.insert(new Count(1));</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; session.fireAllRules();</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; session.dispose();</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; session = null;</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; System.gc();</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; After GC,&nbsp; workingMemory (session) need to be finally but she isn't </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; because VariableContextEntry/ReturnValueContextEntry keep a </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; reference at </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; the workingMemory.</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; Thanks for your response</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; </FONT></SPAN>

<BR><SPAN LANG="fr"><FONT SIZE=2 FACE="Arial Unicode MS">&gt; Yves</FONT></SPAN>

<BR><SPAN LANG="fr-ch"><FONT FACE="Times New Roman">&gt; </FONT></SPAN>

<BR><SPAN LANG="fr"><FONT SIZE=2 FACE="Arial">&gt; </FONT></SPAN>
</P>

</BODY>
</HTML>