Hi, I have added one field by using session.setAttribute("DBID",dbName); Once use it Is it necessary to remove the attribute by using session.removeAttribute()?
If you know you're done with it and won't need it again, it's not a bad idea to explicitly remove it; especially if it's large or contains references to many other objects.
If you don't remove it, it will be removed when the session is destroyed.
When you are done using an attribute, it's always polite to clean it up and remove it from the session.
I did notice the DBID as the attribute. If the attribute being put in the session is used universally for all users accessing that application, you might want to consider putting it into the ServletContext, as opposed to the session. With a session, the attribute is duplicated for every user. If it's put into the context, every user shares the same value, which is very efficient.
If you don't have future requirement with that object, you can remove it by using session.removeAttribute(); Its not a bad practice.
If you do not remove it at present also,there is no problem.
Because you are storig the object in session, whenever your session time-out is over, then the session object is automatically removed by the web-container.
Chengwei Lee
Ranch Hand
Joined: Apr 02, 2004
Posts: 884
posted
0
Its definitely a good idea to remove it once its no longer in use. House-keeping should be done else you may run out of memory.
If you're dealing with clustering, the more objects you store in the session, the more work the server has to do to replicate the session. And all these add overheads to your server and could affect your application performance.
Unless very necessary, try putting it into the request object, else your application may not be that scalable.
Originally posted by Ben Souther: it's not a bad idea to explicitly remove it
what about the session.invalidate() method ? can we use this instead of removeAttribute() please give us some valuable suggestion to handling with session.
session.invalidate() will invalidate the whole session, including all scope variables set within it. Sort of like using dynamite to open a jar of pickles. [ December 10, 2006: Message edited by: Bear Bibeault ]