Can I have back my destructors, please?



In C++ you have RAII idiom that takes care of all your resources -
memory, file handles, etc.

In C# you have GC that takes care of the memory, but it looks like
you're completely on you own as far as other resources are concerned -
just miss this Dispose() call and wait for all kind of interesting
things to happen.

For every class that you consume the first thing you should note is
whether it implements IDisposable or not, and handle it accordingly.

Now the problem: suppose you use some class, which does not implement
IDisposable. All is well. And then, the maintainer of this class
decides that he needs to use some other object, which does implement
IDisposable, and to make this object a member. Although this should be
just an implementation detail and completely private business, he has
to make his own class implement IDisposable.
And now your code still compiles fine, but is no longer correct,
although the only thing that really has changed is just implementation
of a class you use.

In a sense, whether some class implements IDisposable or not is just
an implementation artifact for the author, but is indeed an interface
change for the consumer.

Actually, I'm still learning C#, so I hope something of what I've
written above is incorrect. Otherwise, please advise how to deal with
the problem I've mentioned in practice (is there any way, at least, to
make the consumer code uncompilable after such change?).
.



Relevant Pages

  • Re: GC performance - GC fragility
    ... I rather prefer to know the details, but having not to care about them during coding. ... which does nothing more than allocating memory in an endless loop doesn't eat all the systems memory. ... For these kind of resources even in a GC environment reference counting is needed. ... If my application has a significant performance decrease, when using .NET compare to the native implementation then yes, I wouldn't let the customer pay for it. ...
    (borland.public.delphi.non-technical)
  • Re: Can I have back my destructors, please?
    ... memory, file handles, etc. ... And now your code still compiles fine, but is no longer correct, ... make the consumer code uncompilable after such change?). ... with a destructor and the compiler takes care of calling Dispose at the ...
    (microsoft.public.dotnet.languages.vc)
  • Can I have back my destructors, please?
    ... In C++ you have RAII idiom that takes care of all your resources - ... memory, file handles, etc. ... make the consumer code uncompilable after such change?). ...
    (microsoft.public.dotnet.languages.vc)
  • Re: silver certificates
    ... 50%) of the worlds resources. ... Denmark, Switzerland, and Japan) have consumer the vast majority of the ... world's resources since the end of the Second World War" ... care as, say, Mali? ...
    (rec.collecting.coins)
  • Re: Sad Commentary
    ... Why are so many people fawning over the memory of somebody who obviously ... ill or not and could care less in any event. ... focusing efforts and resources upon treatment, ... CII assistance includes child and family assessment supported by ...
    (soc.retirement)