Originally posted by Alok Pota:
Are user objects bound to the request, session, pagecontext, application objects of a JSP stored in the Java heap? The servlet API offers some control over session bound objects why is there no control provided for page/application and request bound objects?
When do all these objects become available for GC?.
These objects are stored where you allocate all Java objects -- which, indeed, is the heap.
With "control" I assume you mean HttpSessionBindingListener. The reason you need it is that a session can be expired anytime by the server. The lifecycle of all other scopes is a lot more predictable:
- Page scoped objects are essentially local variables, they are released when you leave the page.
- Request scoped objects are released when you've reached the last servlet in the chain processing the request.
- Application scoped objects stay around until the server reclaims the ServletContext (usually only when it is shut down). I think this is the only one where you might wish for a HttpSessionBindingListener equivalent.
When these objects are eligible for garbage collection is not up to the implementor of the JSP engine, but defined in the JSP specification. When the garbage collection actually happens is undetermined, as always.
- Peter