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/28 13:38:00 UTC

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

     [ https://issues.apache.org/jira/browse/MYFACES-4433?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Volodymyr Siedlecki resolved MYFACES-4433.
------------------------------------------
    Resolution: Fixed

> 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.2.14, 3.0.1, 2.3.9, 2.3-next-M6
>            Reporter: Volodymyr Siedlecki
>            Priority: Major
>             Fix For: 2.0.25, 2.3.10, 2.3-next-M7, 3.0.2
>
>         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)