Re: Class Destructor doesn't destroy?

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



"Gerry Hickman" <gerry666uk@xxxxxxxxxxxxxxxx> wrote in message
news:uER06v1XIHA.536@xxxxxxxxxxxxxxxxxxxx
If I instantiate a Class using operator new, I can destroy it with
operator delete, but if I instantiate it without operator new, I don't
seem to be able to destroy it until it goes out of scope - manually
calling the destructor doesn't completely destroy it.

More precisely, your program exhibits undefined behavior under C++
stanadard 3.8/8:

If a program ends the lifetime of an object of type T with static
(3.7.1) or automatic (3.7.2) storage duration and if T has a non-trivial
destructor, the program must ensure that an object of the original type
occupies that same storage location when the implicit destructor call
takes place; otherwise the behavior of the program is undefined.

"Undefined behavior" here means the program can do anything, including
calling the destructor twice. See also

http://www.faqs.org/docs/jargon/N/nasal-demons.html

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: Dopey Delphi
    ... Destroy, ... The destructor releases the memory. ... FreeAndNil which can hide some nasty bugs). ... there is quite a lot of that in Delphi by now. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Multiple destructors?
    ... and it seemed to me that destroying a file object might be a ... > Destroy would just destroy the list, ... For it is the destructor called by Free. ... Actually, on checking, all virtual methods in TObject are in the ...
    (comp.lang.pascal.delphi.misc)
  • Re: Class Destructor doesnt destroy?
    ... the destructor won't be called ... Microsoft MVP, MCSD ... operator delete, but if I instantiate it without operator new, I don't ... seem to be able to destroy it until it goes out of scope - manually ...
    (microsoft.public.vc.language)
  • Re: Multiple destructors?
    ... There are filesystem, file, and directory ... > "the" destructor is taken, ... > It is possible to have detached file and directory objects, ... class of Tlist DONE instead of DESTROY. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Is this code correct?
    ... So a pointer is copied. ... > destructor, which is Undefined Behavior (crash, hang, e-mail to Bush). ...
    (comp.lang.cpp)