Click here to Skip to main content
12,819,913 members (32,662 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP ASP.NET
Hi friends.
I have a question about session expiration.
does the memory that is for a variable get clear when session expires?
in the other words can we use our global variables after session expiration?
thanks in advanced.
Posted 5-Jul-12 22:38pm
kornakar 6-Jul-12 3:47am
I think you should avoid using global variables as much as possible. Try to think another way of doing what you want (cookies perhaps, or a database?).

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

A variable is cleared when you are not using it and the garbage collector is ready to clean it up.
This has nothing to do with session variables.

Session state is nothing more than memory in the shape of a dictionary or hash table, e.g. key-value pairs, which can be set and read for the duration of a user's session. This dictionary is linked to the session.
Once the timeout expires, ASP.NET terminates an inactive Session and disposes of the state for that session.
Thus the dictionary is destroyed.

Thus from your question's point of view, the variable and session stated are independent things and one being disposed does not mean the other has been disposed.

These are some great links -[^].[^]
Manas Bhardwaj 6-Jul-12 3:54am
Well exlained +5
Abhinav S 6-Jul-12 3:55am
Thank you Manas.
Rahul Rajat Singh 6-Jul-12 3:55am
Pranit Kothari 6-Jul-12 3:58am
Abhinav S 6-Jul-12 3:59am
Thank you Rahul.
Abhinav S 6-Jul-12 3:59am
Thank you.
Pooyan Behroozfar 6-Jul-12 4:01am
thank you my friend.
Abhinav S 6-Jul-12 4:03am
You are welcome.
Mohd Imran Saifi 6-Jul-12 4:18am
very good expalnation.
Abhinav S 6-Jul-12 4:30am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 6 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100