View Full Version : Releasing Session Variables

02-19-2003, 02:56 PM
How do you release a session variable so it no longer exists.

Ive tried setting them to null, nothing and vbempty, the variable is empty but an instance of it is still there. I need to completely remove any trace of the session variable so it wil not be picked up using the following code

Dim x
dim session_list

for x = 1 to session.Contents.Count

session_list = session_list & "|" & Session.Contents.Key(x) & "~" & Session.Contents.Item(x)



I thought this would be a simple procedure but I cant find any resources on the net to do this.

Any help would be greatly appreciated.



02-19-2003, 03:33 PM
why not use something like this:

Dim sessitem
For Each sessitem in Session.Contents
if session.Contents(sessitem) <> "" then
Response.write(sessitem & " : " & Session.Contents(sessitem) & "<BR>")
end if

-->inserting a condition to filter out the empty ones from the collection.

Setting them to nothing clears the space that the session-variable used, but doesn't remove it from the session collection because it has session scope it (since it doesn't take up space, why bother ?). Session object can only be destroyed by using abandon or when session terminates.

More info from helpfile:

To create an object with session or application scope, you can either use the <OBJECT> tag and set the SCOPE attribute to SESSION or APPLICATION, or store the object in a session or application variable.

For example, an object stored in a session variable, as shown in the following script, is destroyed when the Session object is destroyed. That is, when the session times out, or the Abandon method is called.

<% Set Session("ad") = Server.CreateObject("MSWC.AdRotator")%>

02-26-2003, 10:44 AM
Hi steveg

To completely remove the session variable itself you have to use the REMOVE method

If you're just looking to remove one session variable then the code would be:

If you want to remove all session variables, for instance on a logout event, then use this...

Let me know if that works.

dominicall :)