Re: Class Destructor doesn't destroy?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC 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: 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: PreTranslateMessage gets called wrongly (after view destroyed)
    ... leave the destructor to actual memory deallocation of items that need it? ... deleting the controls only sends messages asking them to ... destroy themselves, so that should be done within the MFC destruction ... leaving the CPP destruction process to actually release memory as ...
    (microsoft.public.vc.mfc.docview)
  • Re: Disposing. My objects wont destroy
    ... destroy your objects, and the destructor will be called then. ... to ensure that expensive resources like database connections ... destructor and a Dispose method. ...
    (microsoft.public.dotnet.languages.csharp)