You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Volodymyr Siedlecki (Jira)" <de...@myfaces.apache.org> on 2022/04/27 19:54:00 UTC

[jira] [Created] (MYFACES-4433) Memory Leak with ViewScopeBeanHolder's storageMap

Volodymyr Siedlecki created MYFACES-4433:
--------------------------------------------

             Summary: Memory Leak with ViewScopeBeanHolder's storageMap
                 Key: MYFACES-4433
                 URL: https://issues.apache.org/jira/browse/MYFACES-4433
             Project: MyFaces Core
          Issue Type: Bug
          Components: JSR-344, JSR-372
    Affects Versions: 2.3-next-M6, 2.3.9, 2.2.14
            Reporter: Volodymyr Siedlecki
         Attachments: image-2022-04-27-15-35-40-508.png

Hello,

This memory leak issue pertains to ViewScope beans's storage object.  As you recall, ViewScope beans are deleted once the view changes, or the session expires. 

If you look a the code link, you'll see that when ViewScopeBeanHolder#getContextualStorage is called, a new contextualStorage (to store ViewScoped beans) is created and stored within storageMap .  For every new view created, a new object is created and add this map. 

[https://github.com/apache/myfaces/blob/2.2.x/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java#L90-L94]


When the session expires, the storageMap is cleared via forceNewStorage.  (ViewScopeBeanHolder#destroyBeansOnPreDestroy’s PreDestroy annotation) This is fine. 

https://github.com/apache/myfaces/blob/2.2.x/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java#L180-L193 

https://github.com/apache/myfaces/blob/2.2.x/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java#L135

However, if the view changes, the beans are destroyed, but the contextualStorage (which holds the beans) still exists in the storageMap.  The only things that happens currently are the context here is cleared and storage is deactivated. 

[https://github.com/apache/myfaces/blob/2.2.x/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextImpl.java#L256-L258]

 The memory growth is small, but can still add up over time.  Here's a screenshot of the leak: 

!image-2022-04-27-15-35-40-508.png!

This seems like a bug to me as I don't see any use for the contextualStorage once it's deactivated.  Therefore, I've attached a PR to address this issue.  Thanks!



--
This message was sent by Atlassian Jira
(v8.20.7#820007)