包含实现 IDisposable 的项目的会话 [英] Session containing items implementing IDisposable

查看:16
本文介绍了包含实现 IDisposable 的项目的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ASP.NET 中,如果项目留在会话状态中,实现 IDisposable 但在会话到期时从未被应用程序专门删除和处置,将对 Dipose() 中的任何代码将执行的对象调用 Dispose?

In ASP.NET if items are left in the session state that Implement IDisposable but are never specifically removed and disposed by the application when the session expires will Dispose be called on the objects that any code in Dipose() will execute?

推荐答案

如果 IDisposable 模式是 正确实现,然后是的(即类的析构函数将负责处理对象).我不相信 ASP.NET 会话管理器对在实现 IDisposable 的类上显式调用 Dispose() 做出任何保证.

If the IDisposable pattern is implemented properly, then yes (i.e. the class's destructor will take care of disposing the object). I don't believe the ASP.NET session manager makes any guarantees about explicitly calling Dispose() on classes implementing IDisposable.

请注意,尽管 Mark 强烈反对,但我并不是建议常规"添加终结器.我只是建议,如果您想要在会话到期时调用的对象上的 Dispose 方法,这是一个可行的选择.

Note that despite Mark's aggressive objections, I am not suggesting "routinely" adding finalizers. I am simply suggesting that if you want the Dispose method on your object called when the session expires, this is a viable option.

这篇关于包含实现 IDisposable 的项目的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆