You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by carl ballantyne <ca...@cast-info.es> on 2010/03/09 11:46:43 UTC

StrutsSpringTestCase - Memory Leak

Hi All,

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.

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);
     }

Hope this helps anyone who runs into the same issue.
Cheers,
Carl.


*Advertencia legal: en virtud de lo establecido en la Ley Organica 15/1999 de Proteccion de Datos de Caracter Personal, le informamos de que los datos personales que pueda facilitarnos se incorporaran a un fichero automatizado titularidad de CAST INFO, S.A. con la finalidad de gestionar la relacion negocial que nos vincula. Podra revocar su consentimiento al tratamiento de los datos, asi como ejercer sus derechos de acceso, rectificacion, cancelacion u oposicion dirigiendose por escrito a CAST INFO domiciliada en C/ Tuset 23, 1 -- 08006 Barcelona, o a la direccion de correo electronico lopd@cast-info.es.

Este mensaje y los ficheros anexos que pueda contener son confidenciales, pueden contener informacion sometida a secreto profesional y se dirige exclusivamente a su destinatario. Si ha recibido este mensaje por error o tiene conocimiento del mismo por cualquier motivo, le rogamos que nos lo comunique inmediatamente por este mismo medio y se abstenga de utilizarlo, reproducirlo, alterarlo, archivarlo o comunicarlo a terceros. El emisor no se responsabiliza de posibles perjuicios derivados de la captura, incorporaciones de virus o cualesquiera otras manipulaciones efectuadas por terceros.

Antes de imprimir este e-mail piense bien si es necesario hacerlo.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: StrutsSpringTestCase - Memory Leak

Posted by Martin Gainty <mg...@hotmail.com>.
can you update the StrutsSpringTestCase in the repository?
Many Thanks for this important discovery and the solution!

Saludos Cordiales desde EEUU
Martin 
______________________________________________ 
Porfavor no modifica o interrupta esa communicacion/Please do not modify or interrupt this communication


> Date: Tue, 9 Mar 2010 11:46:43 +0100
> From: carl.ballantyne@cast-info.es
> To: user@struts.apache.org
> Subject: StrutsSpringTestCase - Memory Leak
> 
> Hi All,
> 
> 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.
> 
> 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);
>      }
> 
> Hope this helps anyone who runs into the same issue.
> Cheers,
> Carl.
> 
> 
> *Advertencia legal: en virtud de lo establecido en la Ley Organica 15/1999 de Proteccion de Datos de Caracter Personal, le informamos de que los datos personales que pueda facilitarnos se incorporaran a un fichero automatizado titularidad de CAST INFO, S.A. con la finalidad de gestionar la relacion negocial que nos vincula. Podra revocar su consentimiento al tratamiento de los datos, asi como ejercer sus derechos de acceso, rectificacion, cancelacion u oposicion dirigiendose por escrito a CAST INFO domiciliada en C/ Tuset 23, 1 -- 08006 Barcelona, o a la direccion de correo electronico lopd@cast-info.es.
> 
> Este mensaje y los ficheros anexos que pueda contener son confidenciales, pueden contener informacion sometida a secreto profesional y se dirige exclusivamente a su destinatario. Si ha recibido este mensaje por error o tiene conocimiento del mismo por cualquier motivo, le rogamos que nos lo comunique inmediatamente por este mismo medio y se abstenga de utilizarlo, reproducirlo, alterarlo, archivarlo o comunicarlo a terceros. El emisor no se responsabiliza de posibles perjuicios derivados de la captura, incorporaciones de virus o cualesquiera otras manipulaciones efectuadas por terceros.
> 
> Antes de imprimir este e-mail piense bien si es necesario hacerlo.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/201469230/direct/01/

Re: StrutsSpringTestCase - Memory Leak

Posted by Lukasz Lenart <lu...@googlemail.com>.
2010/3/9 carl ballantyne <ca...@cast-info.es>:
> Done - https://issues.apache.org/jira/browse/WW-3402.

And done from my side ;-)


Best regards
-- 
Łukasz
http://www.lenart.org.pl/
Kapituła Javarsovia 2010
http://javarsovia.pl

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: StrutsSpringTestCase - Memory Leak

Posted by carl ballantyne <ca...@cast-info.es>.
Done - https://issues.apache.org/jira/browse/WW-3402.

Quoting Lukasz Lenart <lu...@googlemail.com>:

>
> Could you register a new issue with patch attached?
> https://issues.apache.org/jira/browse/WW
>
>



*Advertencia legal: en virtud de lo establecido en la Ley Organica 15/1999 de Proteccion de Datos de Caracter Personal, le informamos de que los datos personales que pueda facilitarnos se incorporaran a un fichero automatizado titularidad de CAST INFO, S.A. con la finalidad de gestionar la relacion negocial que nos vincula. Podra revocar su consentimiento al tratamiento de los datos, asi como ejercer sus derechos de acceso, rectificacion, cancelacion u oposicion dirigiendose por escrito a CAST INFO domiciliada en C/ Tuset 23, 1 -- 08006 Barcelona, o a la direccion de correo electronico lopd@cast-info.es.

Este mensaje y los ficheros anexos que pueda contener son confidenciales, pueden contener informacion sometida a secreto profesional y se dirige exclusivamente a su destinatario. Si ha recibido este mensaje por error o tiene conocimiento del mismo por cualquier motivo, le rogamos que nos lo comunique inmediatamente por este mismo medio y se abstenga de utilizarlo, reproducirlo, alterarlo, archivarlo o comunicarlo a terceros. El emisor no se responsabiliza de posibles perjuicios derivados de la captura, incorporaciones de virus o cualesquiera otras manipulaciones efectuadas por terceros.

Antes de imprimir este e-mail piense bien si es necesario hacerlo.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: StrutsSpringTestCase - Memory Leak

Posted by Lukasz Lenart <lu...@googlemail.com>.
2010/3/9 carl ballantyne <ca...@cast-info.es>:
> Hi All,
>
> 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.
>
> 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);
>    }
>
> Hope this helps anyone who runs into the same issue.
> Cheers,
> Carl.

Could you register a new issue with patch attached?
https://issues.apache.org/jira/browse/WW


Thanks in advance
-- 
Łukasz
http://www.lenart.org.pl/
Kapituła Javarsovia 2010
http://javarsovia.pl

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: StrutsSpringTestCase - Memory Leak

Posted by Martin Gainty <mg...@hotmail.com>.
can you update the StrutsSpringTestCase in the repository?
Many Thanks for this important discovery and the solution!

Saludos Cordiales desde EEUU
Martin 
______________________________________________ 
Porfavor no modifica o interrupta esa communicacion/Please do not modify or interrupt this communication


> Date: Tue, 9 Mar 2010 11:46:43 +0100
> From: carl.ballantyne@cast-info.es
> To: user@struts.apache.org
> Subject: StrutsSpringTestCase - Memory Leak
> 
> Hi All,
> 
> 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.
> 
> 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);
>      }
> 
> Hope this helps anyone who runs into the same issue.
> Cheers,
> Carl.
> 
> 
> *Advertencia legal: en virtud de lo establecido en la Ley Organica 15/1999 de Proteccion de Datos de Caracter Personal, le informamos de que los datos personales que pueda facilitarnos se incorporaran a un fichero automatizado titularidad de CAST INFO, S.A. con la finalidad de gestionar la relacion negocial que nos vincula. Podra revocar su consentimiento al tratamiento de los datos, asi como ejercer sus derechos de acceso, rectificacion, cancelacion u oposicion dirigiendose por escrito a CAST INFO domiciliada en C/ Tuset 23, 1 -- 08006 Barcelona, o a la direccion de correo electronico lopd@cast-info.es.
> 
> Este mensaje y los ficheros anexos que pueda contener son confidenciales, pueden contener informacion sometida a secreto profesional y se dirige exclusivamente a su destinatario. Si ha recibido este mensaje por error o tiene conocimiento del mismo por cualquier motivo, le rogamos que nos lo comunique inmediatamente por este mismo medio y se abstenga de utilizarlo, reproducirlo, alterarlo, archivarlo o comunicarlo a terceros. El emisor no se responsabiliza de posibles perjuicios derivados de la captura, incorporaciones de virus o cualesquiera otras manipulaciones efectuadas por terceros.
> 
> Antes de imprimir este e-mail piense bien si es necesario hacerlo.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/201469230/direct/01/