Re: Can I have back my destructors, please?
- From: "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx>
- Date: Wed, 20 Feb 2008 18:42:51 -0800
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
.
- Follow-Ups:
- Re: Can I have back my destructors, please?
- From: Tamas Demjen
- Re: Can I have back my destructors, please?
- References:
- Can I have back my destructors, please?
- From: cctv . star
- Can I have back my destructors, please?
- Prev by Date: Can I have back my destructors, please?
- Next by Date: Re: Can I have back my destructors, please?
- Previous by thread: Can I have back my destructors, please?
- Next by thread: Re: Can I have back my destructors, please?
- Index(es):
Relevant Pages
|