I suggest taking the responses to your question and posting to the drools mailing list if there is one.
The fix needs to be made by whatever code is managing the Interpreter creation and freeing.
----- Original Message -----
From: Atul Bisaria
To: David A. Lee ; beanshell-users@lists.sourceforge.net
Cc: stewart.cambridge@gmail.com
Sent: Wednesday, October 22, 2008 1:03 AM
Subject: RE: [Beanshell-users] Memory leak using Beanshell.

Hi David and Stewart,


Thanks for your replies.


I am not sure of any cyclic dependencies, but on checking the results from the Java profiling tool, I observed that int[] and char[] objects are eating up 80% of the memory. On looking into the beanshell APIs I observed that these objects are initialized during the call to bsh.Interpreter.eval() method and never cleaned up or released later until the server is stopped.


My problem is that our application does not call beanshell APIs directly. It invokes some of the Drools (www.jboss.org/drools/) APIs which in turn use the beanshell APIs. I cannot make changes to the Drools library, so in effect, I donít have any handle from where I can make changes to the call to bsh.Interpreter or make changes to the finalize() call, as suggested by Stewart.


I tried using the latest downloadable version of beanshell, i.e. bsh-2.0b4.jar, hoping that memory leak issue is resolved in this one, but there has been a change in some of the APIs in this version so I canít use it.


Thanks and Regards,

Atul Bisaria

Senior Associate

Headstrong Services, D-4, Sector 59, Noida, India. 



From: David A. Lee [mailto:dlee@calldei.com]
Sent: Tuesday, October 21, 2008 6:27 PM
To: Atul Bisaria; beanshell-users@lists.sourceforge.net
Subject: Re: [Beanshell-users] Memory leak using Beanshell.


In my app I once had this problem.  I discovered some circular dependancies in my app which were causing beanshell to hold onto an instance of hte interpreter.   A critical point is that if any of the rules keep an instance to any class that in turn references the interpreter, it can consume memory in a way the GC doesnt detect.  To clean up from this, its important that you dont store multiple references to the interpreter, especially in any objects you create from BS scripts.  Or if you do, you need to break the cycle of referencs.  To discover these, I used a Java memory tool,

JProfiler .. and looked for where the interpreter references were being held.  Its important to clear ALL references to the interpreter when you release it or it may leak.   Once I fixed that up (no changes to BSH internals) it stopped leaking, and I can run for months without any increase in memory use, loading scripts over and over.



----- Original Message -----

From: Atul Bisaria

To: beanshell-users@lists.sourceforge.net

Sent: Tuesday, October 21, 2008 8:38 AM

Subject: [Beanshell-users] Memory leak using Beanshell.




I am using Beanshell version 1.2-b3. I am using it inside Jetty application server. Whenever I hot deploy the application, the Jetty server does not restart but the Beanshell loads the rules file in the application again. Repeatedly hot deploying the application is resulting in memory leak due to Beanshell (checked it from a Java profiling tool) and an OutOfMemory exception is thrown.


Please let me know if there is a fix or a patch available to resolve memory leak in Beanshell?


Thanks and Regards,

Atul Bisaria

Senior Associate

O: +91 95120 4075267 | M: +91 9818611147

Headstrong Services, D-4, Sector 59, Noida, India. 



This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world

Beanshell-users mailing list