You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Carl Ballantyne (JIRA)" <ji...@apache.org> on 2010/03/09 15:14:27 UTC

[jira] Created: (WW-3402) StrutsSpringTestCase - Memory Leak

StrutsSpringTestCase - Memory Leak
----------------------------------

                 Key: WW-3402
                 URL: https://issues.apache.org/jira/browse/WW-3402
             Project: Struts 2
          Issue Type: Bug
          Components: Unit Tests
    Affects Versions: 2.1.8
         Environment: Eclipse 3.5, Linux Fedora 10.
            Reporter: Carl Ballantyne


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());
        }
       
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
applicationContext);
    }

Maybe someone can update the repository with this.

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


[jira] Resolved: (WW-3402) StrutsSpringTestCase - Memory Leak

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3402?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart resolved WW-3402.
-------------------------------

       Resolution: Fixed
    Fix Version/s: 2.2.0
         Assignee: Lukasz Lenart

Patch applied and committed, revision 920892

Bets regards
--
Lukasz

> StrutsSpringTestCase - Memory Leak
> ----------------------------------
>
>                 Key: WW-3402
>                 URL: https://issues.apache.org/jira/browse/WW-3402
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Unit Tests
>    Affects Versions: 2.1.8
>         Environment: Eclipse 3.5, Linux Fedora 10.
>            Reporter: Carl Ballantyne
>            Assignee: Lukasz Lenart
>             Fix For: 2.2.0
>
>
> 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());
>         }
>        
> servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
> applicationContext);
>     }
> Maybe someone can update the repository with this.

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