views:

178

answers:

1

I'm using a SessionObject which is stored inside a database. The SessionObject is wrapped inside SessionObjecWrapper which implements IDisposable. The SessionObjectWrapper is then placed in HttpContext.Current.Session.

On session expiration, does ASP.NET "dispose" (or lets the GC do just that) of any object inside the session?

And on application shutdown?

I'm testing this and I'm not seeing this happen. How should I make this happen in a clean way?

+2  A: 

You can dispose the objects yourself, or use a finalizer method instead. The GC will never call Dispose(), but it will call the finalizer.

I don't know what you need to do in your Dispose(). Some things are not possible in a finalizer (like accessing other managed objects)

chris166
Ok, that means I'll have to implement Session_End and iterate over the items in the session and call Dispose on those that implement IDisposable>
Jaap