How can I clear a session variable?

Is there a one liner to clear a session variable?

I need to clear a dataset in session when "not ispostback"...

thx.
Weller0123Asked:
Who is Participating?
 
b1xml2Commented:
plus this.

Session("keyName") = Nothing  
does not remove the item. It just sets the Item as Nothing. The item is still in the Session.

Session.Remove("keyName") removes the Item completely.

Session("Item") = 1
Response.Write(Session.Count & "<br>")
Session("Item") = Nothing
Response.Write(Session.Count & "<br>")
Session.Remove("Item")
Response.Write(Session.Count)


wil give you

1 'set to 1
1 'set to nothing
0 'remove
 
0
 
softplusCommented:
Session("mydataset") = Nothing
:)
0
 
raterusCommented:
that's two lines, btw, the smiley will produce a compilation error :-)
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
softplusCommented:
oops:
 Session("mydataset") = Nothing ' :)
0
 
raterusCommented:
there is nothing to smile about, you are murdering the poor session variable!
0
 
softplusCommented:
Session("yourdataset") = Nothing ' for you, all for me
0
 
b1xml2Commented:
Session.Remove("keyName") is arguably more intuitive
0
 
softplusCommented:
If he wanted to reuse the same variable with something else, wouldn't it make sense to set it to Nothing instead of removing it? Or does that have no influence? (just wondering)
0
 
b1xml2Commented:
dunno. but it would be best to not have items in the session set to nothing... after all whether it is there or not
If Session("Item") Is Nothing Then
...
End If

would amount to the same thing.
0
 
khacduystCommented:
hi Weller0123,
if u want to remove session variable u just set it value is nothing and then GC collect it and free memory of webserver the syntax below :
Session("variable name") = Nothing  

or remove it using :
Session.Remove("variable name")

good luck   : )
0
 
b1xml2Commented:
khacduyst,  welcome to EE. Part of the rules in EE is not to repeat the answers given by other experts. You just did that. So please do not do that in the future again.
0
 
Weller0123Author Commented:
LOL!!!!!!!  @  this thread.

I don't know whether to award points on content or comedic value.
0
 
softplusCommented:
To be (removed) or to be nothing :)
0
 
raterusCommented:
That was the question,
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous instantiation,
Or to take arms against a sea of exceptions...
0
 
b1xml2Commented:
LOL raterus,
mine tongue doth not gainsyeth thee that there ever was such a poetic soul as thee fighting the unseemly sea of exceptions.

[Now see what you have started =P~~]
0
 
raterusCommented:
Good Night, Good night!

Parting is such sweet sorrow, that I shall say good night till it be morrow!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.