Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
Core 2.3.3
-
None
-
Linux OS running turbine 2.3.3 & tomcat
Description
We have been aware of a memory leak in our system for several years. After other alterations to our code base it finally reached a stage where we could get an OutOfMemoryError in a couple of days.
So after spending days trying to find a memory leak in our system I finally pinpointed a leak.
http://svn.apache.org/repos/asf/turbine/core/branches/TURBINE_2_3_BRANCH/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaBaseFactory.java
This class has a hashmap called classCache which uses className (a StringBuffer) as a key.
You cannot use StringBuffer as a key in a hashmap as it does not override Object's hashCode() method.
I attached a debugger and saw the number of items in this map incrementing even though I was returning to a page which was already in the map.
One potential fix is just to call toString() on className when putting it into the classCache. However as you are only concatenating 5 items className could be changed to a String as follows:
String className = it.next() + "." + packageName + "." + name;
This is less code and also removes the need for the toString() method on subsequent uses of the className.
Patch:
85,91c85
< StringBuffer className = new StringBuffer();
<
< className.append(it.next());
< className.append('.');
< className.append(packageName);
< className.append('.');
< className.append(name);
—
> String className = it.next() + "." + packageName + "." + name;
100c94
< servClass = Class.forName(className.toString());
—
> servClass = Class.forName(className);