tags:

views:

1085

answers:

2

I am working on an application that has a navigation tree which is a session bean. Every time I invoke the page that contain this bean, my memory usage will increase. However, after few hours of inactivity, the memory still isn't freed. Are there any ideas why this happens, or workarounds?

+2  A: 

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

Ultimately, this is in the control of the container - the server manages when to release resources regardless of the logical expiry settings.

You can help diagnose what is going on using listeners. For example, you could have your bean class implement HttpSessionBindingListener. It will be notified when it is added or removed from a session. Alternatively, you could watch all session events using a HttpSessionAttributeListener (JSF can use the session to manage view state, so expect some entries you didn't define yourself). The HttpSessionAttributeListener is defined in the web.xml:

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


If you're just leaving the server inactive, it may just be that it relies other session requests to trigger expired session cleanup and you're observing an implementation detail. Or you may be leaking memory because you've set a reference to the object in some unmanaged class.

McDowell
+2  A: 

You really need to use a profiler to know what's going on about the memory in a java app. The eclipse profiler is pretty good.

If its a session bean it should not be instantiated for every hit on the page inside the same session.

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

Loki