Re: Destructors are useless?
- From: "Dilip" <rdilipk@xxxxxxxxx>
- Date: 27 Apr 2005 09:20:17 -0700
Michi Henning wrote:
> It is interesting that Java doesn't have this problem. On process
exit, Java
> guarantees
> that destructors (or finalizers, if you prefer) will *not* run. This
means that
> it's perfectly
> safe to put assertions into Java finalizers: while the process is
alive and
> running, the
> assertions are checked whenever the GC decides to garbage collect an
object.
> And, if the process is exiting, destructors don't run at all, meaning
that
> there are
> no issues with respect to destruction order. Of course, that means
that
> assertions
> don't run during process shut down, but at least my process gets to
shut down
> without crashing.
Ok -- so how about this:
class someclass
{
~someclass()
{
try
{
System.Diagnostics.Assert(_myMemVar == null);
}
catch(ObjectDisposedException)
{
// you can't do much here anyway
}
}
}
.
- Follow-Ups:
- Re: Destructors are useless?
- From: Michi Henning
- Re: Destructors are useless?
- References:
- Destructors are useless?
- From: Michi Henning
- Re: Destructors are useless?
- From: Tom Porterfield
- Re: Destructors are useless?
- From: Michi Henning
- Destructors are useless?
- Prev by Date: Double and Parse
- Next by Date: Re: XML Deserialization Newbie Question
- Previous by thread: Re: Destructors are useless?
- Next by thread: Re: Destructors are useless?
- Index(es):
Relevant Pages
|