Re: Can I have back my destructors, please?



cctv.star@xxxxxxxxx wrote:
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?).

Actually, you have all of this if you use managed C++ - you write your class
with a destructor and the compiler takes care of calling Dispose at the
right times.

Apparently, however, you wanted an answer for C#, but you posted in a C++
newsgroup - I'd suggest microsoft.public.dotnet.languages.csharp.

-cd


.



Relevant Pages

  • 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)
  • 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.csharp)
  • 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)
  • Re: GC performance - GC fragility
    ... I take care ). ... memory in an endless loop doesn't eat all the systems memory. ... reference an object that has been collected in the same way that you can ... otherwise allocation a single object would result in 100 ...
    (borland.public.delphi.non-technical)
  • 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)