Re: Destructors are useless?




>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.
.



Relevant Pages

  • Re: Destructors are useless?
    ... > It is interesting that Java doesn't have this problem. ... > that destructors (or finalizers, if you prefer) will *not* run. ... > safe to put assertions into Java finalizers: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Destructors are useless?
    ... That leaves destructors completely useless. ... > for making sure any unmanaged resources are properly released. ... I'd like to write assertions about my own member ... It is interesting that Java doesn't have this problem. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Destructor: not gauranteed to be called?
    ... >between finalizers and destructors, and you expected something of the ... more explanation, but that is the ENTIRE explanation. ... > expectations were justified. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Destructor: not gauranteed to be called?
    ... > implementation detail for destructors in C++. ... Destruction is a language ... Resource automatic freeing (mainly memory), ... The problem is that most developper know about finalizers (which ...
    (microsoft.public.dotnet.languages.vc)
  • Re: finalize() not guaranteed to be called -- ever
    ... >> problem is that objects in variables have value semantics and not ... is also the justification for not including this possibility in Java. ... Just adding destructors ... You suggest that the JVM can just guarantee that finalize() is called, ...
    (comp.lang.java.programmer)