History | Log In     View a printable version of the current page. Get help!  
Issue Details (XML | Word)

Key: STS-279
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Tim Fennell
Reporter: Jay Paulsen
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Stripes

Memory leak in DispatcherHelper

Created: 05/Oct/06 06:34 AM   Updated: 05/Oct/06 07:06 PM
Component/s: None
Affects Version/s: None
Fix Version/s: Release 1.4.2


 Description  « Hide
The private static Map customValidations in DispatcherHelper is never cleared. Since the key to the map entries are Class objects, when a stripes web application is reloaded, this causes the web application classloader to be pinned in memory and it and all the classes it loaded are never garbage collected.

I found this with version 1.4 of stripes and tomcat 5.5.17. The DispatcherHelper code in 1.4.1 looks the same so I imagine the same problem will happen with this version as well.

As a temporary work around, I placed the following code in the contextDestroyed method of a ContextListener class for my web application:

      Field f = DispatcherHelper.class.getDeclaredField("customValidations");
      f.setAccessible(true);
      Map<Class, Method[]> customValidations = (Map<Class, Method[]>) f.get(DispatcherHelper.class);
      customValidations.clear();

It would be nice if stripes exposed a clear method for this field on the DispatcherHelper class so a web app doesn't have to resort this hacked reflection work-around, or better yet, if Stripes had a way to clean it up itself.





 All   Comments   Change History      Sort Order:
Greg Hinkle [05/Oct/06 10:51 AM]
I've seen this before. A good solution would be to switch to WeakHashMap. Should immediately fix the problem as long as nothing else is holding a reference to the class. Now, because Method objects have a reference to their classes, you'll also need to wrap/unwrap the values in the map with WeakReferences.

e.g. map.put(clazz, new WeakReference(methodsArray));


Tim Fennell [05/Oct/06 05:29 PM]
This was a stupid mistake on my part. This code was extracted from the DispatcherServlet where it was non-static, and therefore gc'd properly on redeploy. Greg's fix should be pretty straightforward thought.

Tim Fennell [05/Oct/06 07:06 PM]
Fixed using the WeakHashMap (and value wrapped in a weak reference) solution.