EugeneP
EugeneP

Reputation: 12003

Should values kept in Tomcat Session be set to null when session is being destroyed?

Should values kept in Tomcat Session be set to null when session is being destroyed? Or they are automatically destroyed?

We had a problem with multiple .ser files in tomcat folder. Could that be because we do not set values kept in session to null after using them ?

Upvotes: 2

Views: 410

Answers (2)

BalusC
BalusC

Reputation: 1109062

Should values kept in Tomcat Session be set to null when session is being destroyed? Or they are automatically destroyed?

When a session get invalidated, its attributes will just be dereferenced. When they aren't referenced by any other object, then they will be eligible for GC. Once GC runs, then they will be destroyed, yes.

We had a problem with multiple .ser files in tomcat folder. Could that be because we do not set values kept in session to null after using them ?

No. This sounds like as if Tomcat crashed during startup or shutdown. I'd read the logs.

Upvotes: 2

user159088
user159088

Reputation:

When session is destroyed, any contained objects in the session are also destroyed (i.e. garbage collected if the session is the only one holding on to them). You don't have to set them to null after use.

Tomcat has a feature of serializing sessions on shutdown and trying to re-activate them on start up, called restart persistance. Are you referring to this? If it causes problems for you, it can be deactivated (see the attributes of the standard manager implementation in the same document).

Upvotes: 1

Related Questions