Details
Description
Hello,
This memory leak issue pertains to CDI 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 linked, 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.
When the session expires, the storageMap is cleared via forceNewStorage. (via the SessionScoped ViewScopeBeanHolder#destroyBeansOnPreDestroy’s PreDestroy annotation) This is fine.
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 during this handling are: the context map is cleared and storage is deactivated. The contextualStorage is not removed, however.
The memory growth is small, but can still add up over time. Here's a screenshot of the leak:
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!