struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sean Kleinjung (JIRA)" <>
Subject [jira] Commented: (WW-2167) Memory leak when app stopped
Date Fri, 08 Feb 2008 20:35:39 GMT


Sean Kleinjung commented on WW-2167:

It was certainly no problem to look into this... I was experiencing the same problem with
our in-house integration server. Besides, a lot of the process involved had already been explored
in resources linked to in this thread and elsewhere. In the end, I ended up fixing our application
without having to patch the Struts jar itself. We are using a custom sub-class of FilterDispatcher
that adds the necessary ActionContext cleanup call, which I am attaching to this issue. Simply
add the ActionContextReleasingFilterDispatcher to your project, and use it in the "filter-class"
element in your web.xml instead of org.apache.struts2.dispatcher.FilterDispatcher. Unfortunately,
I found no work-around for the xwork ContainerImpl leaking a reference to InternalContext,
and so you will still need to manually patch your xwork jar.

Keep in mind, also, that having ANY single leak of this type will prevent the entire classloader
(and all of its classes) from being unloaded. So if you want an app to unload cleanly, you
must fix all the issues discussed here, and be prepared to research/resolve problems in other
libraries. See the link I posted earlier for some starting points to look at.

> Memory leak when app stopped
> ----------------------------
>                 Key: WW-2167
>                 URL:
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.0.9
>         Environment: WebSphere (non-network deploy) on Windows XP Professional
> java version "1.5.0"
> Java(TM) 2 Runtime Environment, Standard Edition (build pwi32devifx-20070608 (SR5+IY99712))
> IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223-20070426 (JIT
> J9VM - 20070420_12448_lHdSMR
> JIT  - 20070419_1806_r8
> GC   - 200704_19)
> JCL  - 20070608
>            Reporter: Adam Crume
>             Fix For: 2.1.2
>         Attachments:, log_leak.png
> Struts 2 somehow prevents the app's classes from being garbage collected when the application
is stopped or undeployed.
> I created a barebones Struts 2 app with an action with the following code:
> 	private static final Object x = new Object() {
> 		{
> 			System.out.println("================== Object created: " + hashCode() + " ===================");
> 		}
> 		protected void finalize() throws Throwable {
> 			System.out.println("**************** Object finalized: " + hashCode() + " *********************");
> 		};
> 	};
> Because of this static field, a message should be printed when the class is initialized
and when it is garbage collected.  "Object created" would be printed out whenever I went to
the action for the first time, but restarting the app never printed "Object finalized."  This
is not an issue with garbage collection in my web container because doing the same thing with
a servlet resulted in both messages being printed.
> One problem is that the FilterDispatcher.init() method sets a ThreadLocal but never clears
it.  I fixed that by adding ActionContext.setContext(null); to the end of the init() method,
but that didn't solve the larger problem.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message