[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Pnet-developers] Destructors are not being called - bug or usage er
From: |
Thong (Tum) Nguyen |
Subject: |
RE: [Pnet-developers] Destructors are not being called - bug or usage error? |
Date: |
Mon, 17 May 2004 15:22:24 +1200 |
> -----Original Message-----
> From: Carl-Adam Brengesjo [mailto:address@hidden
> Sent: Monday, 17 May 2004 9:56 a.m.
> To: address@hidden
> Subject: Re: [Pnet-developers] Destructors are not being called - bug or
> usage error?
>
> > David Logan <address@hidden> wrote:
> >
> >OK, technically I can respect that. But in oop-speak, I thought the idea
> >was that code and data were self contained. That statement would mean
> >that a class is responsible for its *own* cleanup. But now, by not
> >requiring destructor calls, the requirement that a class execut its
> >"shutdown code" or "cleanup code" has now been moved to the calling
> >class, hasn't it?
> >
> >David Logan
>
> I have been taught, at least concerning .NET (M$) that the class/object
> should not have to clean up it's mess by itself, though it's a
> good/common programming custom - it's kinda the whole idea with an
> garbage collector and the C# language, indifferent to (ie.) C/C++ where
> it's very important to keep track of the memory usage.
>
> At least this is what Microsoft claims. It was one of the topics that
> were under [heavy] discussion -- on a .NET/C# "propaganda"
> conference/presentation held by Microsoft I attended half a year ago --
> as many C/C++ programmers are, more or less, used to do thier own "dirty
> work".
>
> The destructors >shall< be called prior exit/memory deallocation by the
> framework (read Garbage Collector) - but the exact time of when this id
> done is uncertain.
Personally, I don't think finalizers ("destructors" in C#) should be used
for resource management except to catch cases where the user forgets to call
Dispose/Close. Non-deterministic freeing of resources is often not good
enough. Finalizers may not be called until the end of a program or they may
not even be called at all if you're using a library written by someone who
has written a finalizer that blocks indefinitely. Remember that you can use
the "using" statement to automatically call Dispose/Close.
Although we use a conservative GC, it would be a rare occurrence for an
object's finalizer to not be properly called (unless it's a bug).
One possible improvement on the engine would be to add reference counting to
the engine to support some measure of deterministic finalization (at least
in the non-cyclic reference) case. I'm not sure how useful it would be, but
it would be fun :-).
Regards,
^Tum
- Re: [Pnet-developers] Destructors are not being called - bug or usage error?, (continued)
- Re: [Pnet-developers] Destructors are not being called - bug or usage error?, Rhys Weatherley, 2004/05/14
- RE: [Pnet-developers] Destructors are not being called - bug or usage error?, Thong (Tum) Nguyen, 2004/05/14
- Re: [Pnet-developers] Destructors are not being called - bug or usage error?, David Logan, 2004/05/15
- Re: [Pnet-developers] Destructors are not being called - bug or usage error?, Norbert Bollow, 2004/05/16
- Re: [Pnet-developers] Destructors are not being called - bug or usage error?, Rhys Weatherley, 2004/05/16
- Re: [Pnet-developers] Destructors are not being called - bug or usage error?, Norbert Bollow, 2004/05/17
- Re: [Pnet-developers] Destructors are not being called - bug or usage error?, Carl-Adam Brengesjo, 2004/05/16
- RE: [Pnet-developers] Destructors are not being called - bug or usage error?,
Thong (Tum) Nguyen <=