This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes garbage collecting session objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "garbage collecting session objects" Watch "garbage collecting session objects" New topic

garbage collecting session objects

Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
If we store an object in a session variable and then store another object with the same name the first object is replaced. My question is, do we need to specifically get the original item out and set it to null or will it be eligible to be gc'd automatically as soon as it is replaced?

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12675
When you replace the object, the session no longer has a reference. As long as your program does not have a reference, nobody has a reference and the object will be GCed.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
That's kind of what I thought but wasn't sure.
Thanks Bill
I agree. Here's the link:
subject: garbage collecting session objects
Similar Threads
Invalidation of an existing session
Some listener questions...
Struts Session Scope Listener
How to track all sessions?