Click here to Skip to main content
15,884,628 members
Home / Discussions / C#
   

C#

 
QuestionIDisposable spread Pin
Orjan Westin13-Feb-13 2:45
professionalOrjan Westin13-Feb-13 2:45 
AnswerRe: IDisposable spread Pin
DaveyM6913-Feb-13 4:52
professionalDaveyM6913-Feb-13 4:52 
AnswerRe: IDisposable spread Pin
Keith Barrow13-Feb-13 5:13
professionalKeith Barrow13-Feb-13 5:13 
GeneralRe: IDisposable spread Pin
PIEBALDconsult13-Feb-13 17:46
mvePIEBALDconsult13-Feb-13 17:46 
GeneralRe: IDisposable spread Pin
N a v a n e e t h13-Feb-13 18:59
N a v a n e e t h13-Feb-13 18:59 
GeneralRe: IDisposable spread Pin
Orjan Westin13-Feb-13 22:33
professionalOrjan Westin13-Feb-13 22:33 
AnswerRe: IDisposable spread Pin
N a v a n e e t h13-Feb-13 18:56
N a v a n e e t h13-Feb-13 18:56 
AnswerRe: IDisposable spread Pin
BobJanova13-Feb-13 23:54
BobJanova13-Feb-13 23:54 
Orjan Westin wrote:
Now, the derived classes are already IDisposable from DriverWrapper, but if they only hold delegates, which aren't IDisposable themselves, is there any need to override Dispose(bool) in these? I think not, but I'm no expert on C#.

No. As you say they already implement IDisposable through inheritance, and if they don't specify any expensive resources that you need to clean up before the GC gets around to collecting your object, then you don't need to specify additional dispose behaviour.

Would Model have to be IDisposable?

If you want it to be cleaned up before the GC notices it, then yes. And since it's wrapping a class which you already decided should be disposable, then so should the wrapper, and its Dispose should call the driver's Dispose. These two sets of classes seem so closely related that I wonder if you need to have two sets of classes at all, though.

If not, would ModelA-C need to override Dispose even if they have no further data?

No (see first point).

You need to implement IDisposable if you are allocating resources that you want to have guaranteed return at a known time on, but you don't have sufficient control over the context to explicitly call a close method to release them. It's also convenient to implement it when you do have that context, but you want to use the class in a using(x) block, or if you might forget you're supposed to call a close method (as Dispose will get called in GC cleanup too).

You don't need to implement it if the resources you're allocating in a class are so small and unlimited in number available that you don't mind if they don't get collected for a while. That applies to most managed objects, unless they're really huge and there's a memory impact (though the GC will notice this and run a collection sooner than otherwise), and to unmanaged resources that aren't limited (e.g. non-locking file handles, sockets, bitmap handles etc). The other case is that if you know you need a resource for the entire lifetime of your process you don't need to implement IDisposable either, as the one time that finalisers are guaranteed to be called is in process shutdown (assuming it's a clean shutdown), and even if it doesn't get run, the OS will clean up after you.
Questionpropertygrid double click events Pin
Jone Cunha13-Feb-13 0:56
professionalJone Cunha13-Feb-13 0:56 
AnswerRe: propertygrid double click events Pin
Richard MacCutchan13-Feb-13 1:14
mveRichard MacCutchan13-Feb-13 1:14 
GeneralRe: propertygrid double click events Pin
Jone Cunha13-Feb-13 1:24
professionalJone Cunha13-Feb-13 1:24 
GeneralRe: propertygrid double click events Pin
Richard MacCutchan13-Feb-13 1:44
mveRichard MacCutchan13-Feb-13 1:44 
GeneralRe: propertygrid double click events Pin
Jone Cunha13-Feb-13 1:53
professionalJone Cunha13-Feb-13 1:53 
GeneralRe: propertygrid double click events Pin
Richard MacCutchan13-Feb-13 3:16
mveRichard MacCutchan13-Feb-13 3:16 
GeneralRe: propertygrid double click events Pin
Jone Cunha13-Feb-13 4:45
professionalJone Cunha13-Feb-13 4:45 
GeneralRe: propertygrid double click events Pin
Richard MacCutchan13-Feb-13 5:38
mveRichard MacCutchan13-Feb-13 5:38 
GeneralRe: propertygrid double click events Pin
Jone Cunha13-Feb-13 7:32
professionalJone Cunha13-Feb-13 7:32 
QuestionEnevts in MVC application. Need some Help. Pin
plywoods12-Feb-13 21:09
plywoods12-Feb-13 21:09 
QuestionHow to determine whether the given geo code in within geo fence or not? Pin
Vijay Kanda12-Feb-13 20:57
Vijay Kanda12-Feb-13 20:57 
AnswerRe: How to determine whether the given geo code in within geo fence or not? Pin
Pete O'Hanlon12-Feb-13 23:13
mvePete O'Hanlon12-Feb-13 23:13 
Questioncalling a method in c++ from c# Pin
bonosa12-Feb-13 17:45
bonosa12-Feb-13 17:45 
AnswerRe: calling a method in c++ from c# Pin
N a v a n e e t h12-Feb-13 22:19
N a v a n e e t h12-Feb-13 22:19 
GeneralRe: calling a method in c++ from c# Pin
bonosa13-Feb-13 3:55
bonosa13-Feb-13 3:55 
GeneralRe: calling a method in c++ from c# Pin
N a v a n e e t h13-Feb-13 18:21
N a v a n e e t h13-Feb-13 18:21 
GeneralRe: calling a method in c++ from c# Pin
bonosa14-Feb-13 16:56
bonosa14-Feb-13 16:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.