<!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>Potential memory problems</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Arial">Hi,</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I am fronting my rule engine by a stateless session façade bean, running in a weblogic container. The rule bases are loaded only once via a singleton. </FONT></P>

<P><FONT SIZE=2 FACE="Arial">I was running a profiler over the app and have noticed a lot of rule engine objects still attached to the tree. My stub which invokes the working memory looks like the following: </FONT></P>

<P><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">try</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> {</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">handle = wm.assertObject(shift);</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">wm.assertObject(shiftCalculator);</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">wm.fireAllRules();</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">}</FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">catch</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> (RuntimeDroolsException e) {</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">throw</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> TimesheetServiceUnavailableException(</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#2A00FF" SIZE=2 FACE="Courier New">&quot;Could not add shift to Working Memory&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">, e);</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">}</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">wm.clearAgenda();</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">wm.dispose();</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">LoggingUtils.<I>logMethodFinish</I>(</FONT><I><FONT COLOR="#0000C0" SIZE=2 FACE="Courier New">logger</FONT></I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">, methodName);</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">As you can see if an exception occurs then the dispose method is not run. Could this lead to memory leakage?</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I have subsequently modified the offending stub to include a finally block</FONT>
</P>

<P><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">finally</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> {</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">wm.clearAgenda();</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">wm.dispose();</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">LoggingUtils.</FONT><I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">logMethodFinish</FONT></I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">(</FONT><I><FONT COLOR="#0000C0" SIZE=2 FACE="Courier New">logger</FONT></I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">, methodName);</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">}</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Matt Shaw</FONT>

<BR><FONT SIZE=2 FACE="Arial">Snr Applications Developer</FONT>

<BR><FONT SIZE=2 FACE="Arial">Service Performance &amp; Management Unit</FONT>

<BR><FONT SIZE=2 FACE="Arial">Phone: 3247 8666. ext. 94666</FONT>
</P>

</BODY>
</HTML>
<table><tr><td bgcolor=#ffffff><font color=#000000>This correspondence is for the named persons only. <br>
It may contain confidential or privileged information or both. <br>
No confidentiality or privilege is waived or lost by any mis transmission. <br>
If you receive this correspondence in error please delete it from your system immediately and notify the sender. <br>
You must not disclose, copy or relay on any part of this correspondence, if you are not the intended recipient. <br>
Any opinions expressed in this message are those of the individual sender except where the sender expressly, <br>
and with the authority, states them to be the opinions of the Department of Emergency Services, Queensland.<br>
</font></td></tr></table>