Click here to Skip to main content
Rate this: bad
good
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
Comments
kornakar at 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
good
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 -
http://msdn.microsoft.com/en-us/magazine/cc163730.aspx[^].
http://msdn.microsoft.com/en-us/library/ff647327.aspx#diforwc-ch05_cachingstate[^]
  Permalink  
Comments
Manas Bhardwaj at 6-Jul-12 3:54am
   
Well exlained +5
Abhinav S at 6-Jul-12 3:55am
   
Thank you Manas.
Rahul Rajat Singh at 6-Jul-12 3:55am
   
+5.
Abhinav S at 6-Jul-12 3:59am
   
Thank you Rahul.
Pranit Kothari at 6-Jul-12 3:58am
   
5!
Abhinav S at 6-Jul-12 3:59am
   
Thank you.
Pooyan Behroozfar at 6-Jul-12 4:01am
   
thank you my friend.
Abhinav S at 6-Jul-12 4:03am
   
You are welcome.
Mohd Imran Saifi at 6-Jul-12 4:18am
   
very good expalnation.
Abhinav S at 6-Jul-12 4:30am
   
Thanks.

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

  Print Answers RSS
0 OriginalGriff 410
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 264
3 BillWoodruff 235
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 6 Jul 2012
Copyright © CodeProject, 1999-2014
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