Re: Destructors are useless?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Helge Jensen" <helge.jensen@xxxxxxx> wrote in message
news:uBBMFPySFHA.2304@xxxxxxxxxxxxxxxxxxxxxxx

> The really usefull information: who forgot to call Dispose, is of course
> not available, but I have a nice MixIn class that I can use to record
> the stacktrace when the object is created and that is definatly also
> usefull to know. It gives you a place to start looking.
>
> While you may not be able to do much with the knowledge in your
> finalizer, you can certainly throw an exception (the program *IS*
> broken,... it forgot to call Dispose()) and the runtime may do
> "good-things" with it. In debug mode the Visual IDE pops up a
> messagebox, alerting you to a bug which would otherwise go unnoticed.

Hmmm... The specification says that, if a destructor throws, the exception
is ignored and execution of that destructor is aborted. Given that you cannot
safely assert in a destructor or write to the console, it seems unlikely that
you could safely record a stack trace: after all, the classes you have to use
to record the stack trace may have long since been finalized. And, if you
can record the stack trace, throwing the exception is useless because that
exception won't go anywhere (that's guaranteed by the spec). Ergo,
destructors are useless during process shutdown. And, because I cannot
control when constructors run, they are useless altogether.

Cheers,

Michi.

--
Michi Henning Ph: +61 4 1118-2700
ZeroC, Inc. http://www.zeroc.com

.



Relevant Pages

  • Re: Proper disposal of Word 2007 (12.0) ApplicationClass in non-UI application?
    ... hit my destructor. ... I call a its dispose function which attempts to execute the following ... This quit function works fine during normal runtime, ... from the destructor of my WordManager it gives me the following exception ...
    (microsoft.public.office.developer.automation)
  • Re: Create/Exception then Destruct
    ... > automatically called to dispose of the unfinished object. ... Because a constructor sets the fields of a new object to zero ... > destructor after an exception in the constructor. ...
    (comp.lang.pascal.delphi.misc)
  • RE: Wrapping Word.Application object with an IDisposable class?
    ... there is an unhandled exception in my program, ... Word process is not closed in Dispose method when the application is tested ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Question about garbage collection in in vc++ 2005
    ... version of c++, the Dispose now links to the destructor, how will this ... you need to use destructor syntax. ... the finalizer should never run. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: main form, IDisposable, and Application.Run
    ... exception is thrown between construction and the method call. ... open forms (which would obviously dispose the form). ... Maybe the exception is being thrown from the constructor after all, ...
    (microsoft.public.dotnet.languages.csharp)