You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2014/09/09 22:29:08 UTC

svn commit: r1623879 - /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java

Author: lu4242
Date: Tue Sep  9 20:29:07 2014
New Revision: 1623879

URL: http://svn.apache.org/r1623879
Log:
MYFACES-3924 Memory leak in ViewScopeBeanHolder

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java?rev=1623879&r1=1623878&r2=1623879&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java Tue Sep  9 20:29:07 2014
@@ -145,27 +145,35 @@ public class ViewScopeBeanHolder impleme
         ViewScopeContextualStorage contextualStorage = storageMap.get(viewScopeId);
         if (contextualStorage != null)
         {
-            FacesContext facesContext = FacesContext.getCurrentInstance();
-            if (facesContext == null &&
-                applicationContextBean.getServletContext() != null)
+            try
             {
-                try
+                FacesContext facesContext = FacesContext.getCurrentInstance();
+                if (facesContext == null &&
+                    applicationContextBean.getServletContext() != null)
                 {
-                    ServletContext servletContext = applicationContextBean.getServletContext();
-                    ExternalContext externalContext = new StartupServletExternalContextImpl(servletContext, false);
-                    ExceptionHandler exceptionHandler = new ExceptionHandlerImpl();
-                    facesContext = new StartupFacesContextImpl(externalContext, 
-                            (ReleaseableExternalContext) externalContext, exceptionHandler, false);
-                    ViewScopeContextImpl.destroyAllActive(contextualStorage);
+                    try
+                    {
+                        ServletContext servletContext = applicationContextBean.getServletContext();
+                        ExternalContext externalContext = new StartupServletExternalContextImpl(servletContext, false);
+                        ExceptionHandler exceptionHandler = new ExceptionHandlerImpl();
+                        facesContext = new StartupFacesContextImpl(externalContext, 
+                                (ReleaseableExternalContext) externalContext, exceptionHandler, false);
+                        ViewScopeContextImpl.destroyAllActive(contextualStorage);
+                    }
+                    finally
+                    {
+                        facesContext.release();
+                    }
                 }
-                finally
+                else
                 {
-                    facesContext.release();
+                    ViewScopeContextImpl.destroyAllActive(contextualStorage);
                 }
             }
-            else
+            finally
             {
-                ViewScopeContextImpl.destroyAllActive(contextualStorage);
+                //remove the viewScopeId to prevent memory leak
+                storageMap.remove(viewScopeId);
             }
         }
     }