Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-2167

Memory leak when app stopped

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.9
    • 2.1.8.1
    • None
    • None

    Description

      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.

      Attachments

        1. log_leak.png
          52 kB
          Nicolas Raynaud
        2. FilterDispatcher_leak-fix.java
          21 kB
          Sean Kleinjung
        3. ActionContextReleasingFilterDispatcher.java
          1.0 kB
          Sean Kleinjung

        Activity

          People

            Unassigned Unassigned
            adamcrume Adam Crume
            Votes:
            7 Vote for this issue
            Watchers:
            12 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: