Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
310 views
Welcome To Ask or Share your Answers For Others

1 Answer

I'd disagree with Sean's answer; firstly, finalizers should not be routinely added to classes, even if they are IDisposable - finalizers should only really be used in classes that represent unmanaged resources. Conversely, a class with a finalizer often is also IDisposable.

Re the question: is Dispose() called - no, it isn't. The object will be garbage collected at some point in the future (indeterminate), but that is about it. A finalizer wouldn't add much here, as any encapsulated objects will also already be eligible for collection (assuming that they aren't referenced elsewhere).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...