JSF memory usage Issue when using session beans

I am working on a navigation tree application that is a session bean. Every time I call the page containing this bean, my memory usage will increase. However, after several hours of inactivity, the memory is still not freed. Any ideas why this is happening, or workarounds?

+1


source to share


2 answers


You can explicitly set the session timeout in the deployment descriptor, or you can do it programmatically (although you probably don't want to do this in a JSF application).

Ultimately it's container management - the server manages to free up resources regardless of the logical expiration setting.

You can help diagnose what is happening by using listeners. For example, you could implement the HttpSessionBindingListener bean class . It will be notified when it is added or removed from the session. Alternatively, you can view all session events using the HttpSessionAttributeListener (JSF can use the session to manage the view state, so expect some entries you did not define yourself). The HttpSessionAttributeListener is defined in the web.xml file:



<listener>
    <display-name>MyListener</display-name>
    <listener-class>
        somepackage.MySessionDiagnosticListenerImpl
    </listener-class>
</listener>

      


If you just leave the server idle, it might be relying on other session requests to initiate a cleanup of the expired session and you are observing the implementation details. Or there may be a memory leak because you have established a reference to an object in some unmanaged class.

+2


source


You really need to use a profiler to find out what's going on with memory in your Java application. Eclipse's profiler is pretty good.

If its session is a bean, it doesn't have to be created for every page hit within the same session.



You should also keep in mind that the GC will not collect the classes right away. And GC is not necessarily time dependent.

+2


source







All Articles