Web application
The application died in OutOfMemory. Closed screen management beans are alive and R.I.P.
Suspicious part
Annotation | Namespace | Lifetime |
---|---|---|
@RequestScoped |
javax.enterprise.context.RequestScoped | One HTTP request/response |
@ViewScoped |
javax.faces.view.ViewScoped | While the views are the same |
@SessionScoped |
javax.enterprise.context.SessionScoped | Session start-end |
@ApplicationScoped |
javax.enterprise.context.ApplcationScoped | While the application is running |
@Dependent |
javax.enterprise.context.Dependent | Depends on the scope to which it was injected |
@ConversationScoped |
javax.enterprise.context.ConversationScoped | You can specify the start and end arbitrarily |
@FlowScoped |
javax.enterprise.context.FlowScoped | From start to end of a predefined flow |
Hmm.
** It is convenient if @ViewScoped
is generated when the screen is opened and discarded when it is closed. ** **
You can give @SessionScoped
the information of the logged-in user and create a business screen with @ViewScoped
.
You can also specify the number of View
s that a session holds in web.xml
.
/web.xml
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>sever</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.numberOfLogicalViews</param-name>
<param-value>20</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.numberOfViewsInSession</param-name>
<param-value>20</param-value>
</context-param>
Know if it will be released if the upper limit is exceeded.
When I did something like that, the management bean of @ViewScoped
, which should have been destroyed, was so alive that the memory was crushed.
Apparently, the management bean of @ViewScoped
will not be released unless it has the following pattern.
Therefore, it survives in the following pattern.
Use OmniFaces @ViewScoped instead of the standard @ViewScoped
.
Just use the @ViewScoped
annotation of ʻOmniFaces and it will release it when you pick up the ʻunload
event of your browser.
It is designed so as not to affect the default dependency as much as possible, so I wonder if it can be introduced just to use @ViewScoped
.
I wondered if View would be managed on a screen-by-screen basis, but it's not a screen-based unit, but a component tree-based unit, so it's wrong to expect that it will be released when the screen is closed.
It is a trap behavior that it is not discarded even if the maximum number of logical views is exceeded.
~~ Don't hold the session for a long time & don't make it huge ~~
jsf-2 – Why @ViewScoped Beans that have expired are not destroyed until the session expires stack overflow : JSF 2.2 Memory Consumption: Why does Mojarra keep the ViewScoped Beans of the last 25 Views in Memory?
Recommended Posts