<!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 "smal" 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 "infinity", the maximum size of this memory leak is "~ size(WorkingMemory + Facts) x number rules on the rules base".</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"> <<MemoryLeakTest.zip>> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT FACE="Arial Unicode MS">> </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">> De : </FONT></B> <FONT SIZE=1 FACE="Tahoma">Galante, Yves </FONT></SPAN>
<BR><SPAN LANG="de-ch"><B><FONT SIZE=1 FACE="Tahoma">> Objet : </FONT></B> <FONT SIZE=1 FACE="Tahoma">Potential multi thread error and "smal" memory leak</FONT></SPAN>
<BR><SPAN LANG="de-ch"><FONT SIZE=1 FACE="Tahoma">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> Hi,</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> Class VariableContextEntry and ReturnValueContextEntry are </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> instantiated </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> when Package.addRule called.</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> This class are linked from "Package rules".</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> "Package => ... => VariableContextEntry</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> But class have a reference to the InternalWorkingMemory !</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> "Package => ... => VariableContextEntry => Workingmemory"</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> 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">> WorkingMemory need to be garbage collected, but it isn't </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> because she is </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> referenced by ReturnValueContextEntry and/or </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> VariableContextEntry, and </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> this class keeps an reference to the WorkingMemory.</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> 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">> "smal" memory leak.</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> It is right ?</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> The membre workingMemory can't be removed from </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> VariableContextEntry/ReturnValueContextEntry ?</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> ____________________</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> pseudo code (source : ReteooMannersTest) :</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> final Package ruleBase = new Package( "org.drools.examples.manners" );</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> ruleBase.addRule( getAssignFirstSeatRule() );</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> ...</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> SatefulSession session = ruleBase.newStatefulSession(false);</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> session.insert(new Count(1));</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> session.fireAllRules();</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> session.dispose();</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> session = null;</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> System.gc();</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> After GC, workingMemory (session) need to be finally but she isn't </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> because VariableContextEntry/ReturnValueContextEntry keep a </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> reference at </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> the workingMemory.</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> Thanks for your response</FONT></SPAN>
<BR><SPAN LANG="en-gb"><FONT SIZE=2 FACE="Arial Unicode MS">> </FONT></SPAN>
<BR><SPAN LANG="fr"><FONT SIZE=2 FACE="Arial Unicode MS">> Yves</FONT></SPAN>
<BR><SPAN LANG="fr-ch"><FONT FACE="Times New Roman">> </FONT></SPAN>
<BR><SPAN LANG="fr"><FONT SIZE=2 FACE="Arial">> </FONT></SPAN>
</P>
</BODY>
</HTML>