Re: Destructors are useless?
- From: Mattias Sjögren <mattias.dont.want.spam@xxxxxxxx>
- Date: Thu, 28 Apr 2005 00:09:49 +0200
>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.
If that's the behavior you want, how about
~SomeClass()
{
if ( !Environment.HasShutdownStared ) {
Debug.Assert( ... );
}
}
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
.
- Follow-Ups:
- Re: Destructors are useless?
- From: Michi Henning
- 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: Orb - object request broker - how to use in C#
- Next by Date: Re: using serialization to serialize my objects to hard drive
- Previous by thread: Re: Destructors are useless?
- Next by thread: Re: Destructors are useless?
- Index(es):
Relevant Pages
|