473,322 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to dispose session variables automatically

Hi,

I have some objects that implement IDisposable and they in turn need to
dispose of other objects (Only managed resources are being used).

My objects are held in the HTTP session. Is there a way to get these to be
Disposed properly when the session ends?

I guess I could use the session_end event but apparently it's not a good
idea to rely on this because it might not be called in all circumstances.
Also it's not possible to call dispose of another managed object from inside
a finalizer so I can't do it there.

is there an accepted best practice for this?

Andy
Aug 26 '08 #1
4 3104
"Andy Fish" <aj****@blueyonder.co.ukwrote in message
news:Ok**************@TK2MSFTNGP05.phx.gbl...
Hi,

I have some objects that implement IDisposable and they in turn need to
dispose of other objects (Only managed resources are being used).

My objects are held in the HTTP session. Is there a way to get these to be
Disposed properly when the session ends?

I guess I could use the session_end event but apparently it's not a good
idea to rely on this because it might not be called in all circumstances.
Also it's not possible to call dispose of another managed object from
inside
a finalizer so I can't do it there.

is there an accepted best practice for this?
Yeah don't store IDisposable objects in the session ;)

Seriously though first consider whether you really need to be holding
disposable types. If you need to hold these types it will be because they
internally hold something disposable can those internal references be
disposed before the end of a request?

How unreliable do you think Session_End is? If occasionally it doesn't run
is it a disaster that sometimes things have to wait until a GC run to be
tidy up? After all its likely the session has been hanging around idle for
a while anyway.
--
Anthony Jones - MVP ASP/ASP.NET
Aug 26 '08 #2
After serious thinking Anthony Jones wrote :
>
How unreliable do you think Session_End is?
Apparently if you use something other than InProc storage for the
session, the Session_End is never called.

Hans Kesting
Aug 27 '08 #3
"Hans Kesting" <ne*********@spamgourmet.comwrote in message
news:OS**************@TK2MSFTNGP06.phx.gbl...
>>
How unreliable do you think Session_End is?

Apparently if you use something other than InProc storage for the session,
the Session_End is never called.
Correct.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 27 '08 #4
"Hans Kesting" <ne*********@spamgourmet.comwrote in message
news:OS**************@TK2MSFTNGP06.phx.gbl...
After serious thinking Anthony Jones wrote :

How unreliable do you think Session_End is?

Apparently if you use something other than InProc storage for the
session, the Session_End is never called.
Umm.. ok. are you using Out of Proc storage?

Is it possible to store objects that truely need to be disposed (due to
using an unmanaged resource) in an out-of-proc store?

There are three nominal ways a session ends, it times out due to being idle,
a deliberate user action or if its inproc the process is a victim of
recycling.

If it ends on idle does it really matter that objects aren't immediately
disposed?
If the process terminates naturally then the objects are dropped and any
unmanaged resources would do what they naturally do when a process ends.

If a deliberate user action then code on the server is needed to bring that
about, you could place code there to handle the disposing. Thats pretty
messy.

Like I said you really want to avoid disposable objects being stored in the
session in the first place

--
Anthony Jones - MVP ASP/ASP.NET
Aug 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ray | last post by:
I don't know much about these yet, but I want to be able to pass certain variables to all of my asp pages. What I want to do is read all of the variables from the database on my default.asp page...
14
by: qaz | last post by:
I've always used session cookies in my web sites. However, since more and more people (including me) are starting to disable cookies, I'm beginning to think that I should change my ways and design...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
4
by: Morten | last post by:
Hi! I've been implementing forms based authentication in a web project. It works pretty good. When I log on by clicking the "login" button the following code is executed: if...
4
by: VB Programmer | last post by:
If I have a variable I want to share in my application what is the difference between just declaring a variable (Dim strMyVar as String) and using a session variable (Session("strMyVar"))? When...
11
by: Leon | last post by:
Are dataset automatically stored in memory? Does the dispose() method automatically dispose of the dataset in the code below? Do I have to dispose a dataset from memory or does the dataset...
8
by: Joe Abou Jaoude | last post by:
hi, I have a web app with forms authentication and a timeout session of 20 mins for security reasons. I recently added a feature that allows users (if they want to) to automatically log in...
5
by: Ed | last post by:
I have some questions in regards to Session variables and IIS Recycling: 1. Does the IIS setting 'Shutdown worker process after being idle' affect an application's session variables? Or is IIS...
3
by: damezumari | last post by:
To find out were session variables are stored I included this instruction in my program: echo ini_get("session.save_path"); The reply was /home/7604/data/tmp which is a folder on my server. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.