• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Binding user objects to request,session,pagecontext, application

 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?.
 
Bharatesh H Kakamari
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are stored in heap. But when they should be garbage collected depends on the implementor of JSP Engine.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic