You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Adrian Beech <a....@bigpond.net.au> on 2003/10/05 22:41:08 UTC

Blowing away objects that have been stored in the session context

G'day all,

Does Tomcat release all the resources used by an object if the object
has been stored in the session context and a call to
session.removeAttribute("objName") is made?  I'd like to blow away
several beans that are used throughout the processing of a transaction
once the confirmation page is called.

At this stage the only two ways I can think of doing this is to call
session.removeAttribute(...) or retrieve the object from the session
context and then assigning null to it, i.e. myObj = (MyObj)
session.getAttribute("myObjName"); myObj = null;.

Can someone please shed some light on what is best?  Or are these two
possible ways totally off the track?

Thanks if you can help.

AB



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Blowing away objects that have been stored in the session context

Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
> Does Tomcat release all the resources used by an object if the object
> has been stored in the session context and a call to
> session.removeAttribute("objName") is made?  I'd like to blow away
> several beans that are used throughout the processing of a transaction
> once the confirmation page is called.

Calling session.invalidate() should do it for you. It will unbind all objects bound to it, as well as closing the session itself.

> At this stage the only two ways I can think of doing this is to call
> session.removeAttribute(...) or retrieve the object from the session
> context and then assigning null to it, i.e. myObj = (MyObj)
> session.getAttribute("myObjName"); myObj = null;.

The second way will do nothing. session.getAttribute() will give you a reference to an object (which is bound by the session - that is, a reference to it is held in the session) and then you will loose that reference. The object will still live in the session.

Nix.

Re: Blowing away objects that have been stored in the session context

Posted by Tim Funk <fu...@joedog.org>.
No. If it did it would be magical. All objects follow the garbage collection 
rules. So session.removeAttribute("mybean") will remove all known references 
that the tomcat internals point to the reference pointing to "mybean". So for 
mybean to be garbage collected - make sure you have no objects pointing to it.

In a nutshell, session.removeAttribute(..) is all you need. (assuming you 
don't have other variables pointing at that ref)

-Tim

Adrian Beech wrote:

> G'day all,
> 
> Does Tomcat release all the resources used by an object if the object
> has been stored in the session context and a call to
> session.removeAttribute("objName") is made?  I'd like to blow away
> several beans that are used throughout the processing of a transaction
> once the confirmation page is called.
> 
> At this stage the only two ways I can think of doing this is to call
> session.removeAttribute(...) or retrieve the object from the session
> context and then assigning null to it, i.e. myObj = (MyObj)
> session.getAttribute("myObjName"); myObj = null;.
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org