"Andy Fish" <> wrote in message
news:...
> 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