Application Server Solutions for Microsoft IIS and ASP.NET
       solutions   products   partners   company   support   downloads         store
ServletExec Self-Help: FAQ
Back to Search >  Back to Search Results

Faq ID 105
Product ServletExec
Category Session Tracking
Question How can I make sure that the attributes I bind to the Session are cleaned up and don't cause a memory leak?
Answer Every instance of ServletExec has a thread that runs in the background which periodically examines all the session objects it is maintaining. When ServletExec determines that a session has been idle (unused) for a period of time that is longer than the configured session timeout value, it calls invalidate() on the session object. ServletExec's implementation of invalidate() removes all attributes that were bound to that session and then removes any references to the session object itself so that the JVM will be able to garbage collect it (and all of its attributes).
If you have objects (attibutes) which you bind to the session and you want to make certain that those objects correctly, and gracefully, release any resources that they might have acquired (run any cleanup code that you want them to), then you have 2 choices:
  1. Have your objects, that you bind to the session object, implement the javax.servlet.http.HttpSessionBindingListener interface. This way ServletExec will call valueBound() and valueUnbound() methods each time the object is added to or removed from the session. In your implementation of valueUnbound() you would perform any cleanup or resource releasing that you need to do.
  2. Run your code within the context of a Web Application (WEB-INF folder, web.xml file, etc...) and create a listener that will be notified of Session Attribute Change Events. You would do this by implementing the javax.servlet.http.HttpSessionAttributeListener interface.
    In your implementations for attributeReplaced() and attributeRemoved() you would perform any cleanup or resource releasing that you need to do (depending upon which attribute is being removed). The exampleWebApp that comes with ServletExec has a simplistic example of a Session Listener which shows how one might do this. Study this to create your own listener and then configure it in your web app.

company media information terms of use privacy policy contact us