Struts 2
  1. Struts 2
  2. WW-3402

StrutsSpringTestCase - Memory Leak


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.8
    • Fix Version/s: 2.2.1
    • Component/s: Unit Tests
    • Labels:
    • Environment:

      Eclipse 3.5, Linux Fedora 10.


      I ran into an issue with the StrutsSpringTestCase class when doing my unit tests.
      Basically the memory kept climbing until it crashed the machine.

      This class is actually loading the applicationContext for every test case that extends
      it. And because the applicationContext is static the instances of the spring beans loaded
      are not cleaned up by the garbage collector. I could verify this by using JVisualVM and seeing the memory usage climb and by doing a heap dump and seeing the multiple instances of Spring beans.

      What I ended up doing was overriding the method with the following in my base test class
      for Struts 2. The only difference being the check to see if applicationContext is null.
      This has the added benefit of speeding up the tests.

      protected void setupBeforeInitDispatcher() throws Exception {
      // only load beans from spring once
      if (applicationContext == null)

      { GenericXmlContextLoader xmlContextLoader = new GenericXmlContextLoader(); applicationContext = xmlContextLoader.loadContext(getContextLocations()); }


      Maybe someone can update the repository with this.


        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        10m 6s 1 Lukasz Lenart 09/Mar/10 14:23
        Resolved Resolved Closed Closed
        964d 7h 47m 1 Lukasz Lenart 28/Oct/12 22:11
        Lukasz Lenart made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Lukasz Lenart made changes -
        Fix Version/s 2.2.1 [ 12315170 ]
        Fix Version/s 2.2.0 [ 12314680 ]
        Lukasz Lenart made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Lukasz Lenart [ lukaszlenart ]
        Fix Version/s 2.2.0 [ 12314680 ]
        Resolution Fixed [ 1 ]
        Lukasz Lenart added a comment -

        Patch applied and committed, revision 920892

        Bets regards


        Lukasz Lenart added a comment - Patch applied and committed, revision 920892 Bets regards – Lukasz
        Carl Ballantyne created issue -


          • Assignee:
            Lukasz Lenart
            Carl Ballantyne
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: