destructor, postblit constructor --- force calling always

Benjamin Thaut code at benjamin-thaut.de
Mon Mar 31 09:51:21 PDT 2014


Am 31.03.2014 08:06, schrieb monarch_dodra:
> On Monday, 31 March 2014 at 01:03:22 UTC, Carl Sturtivant wrote:
>> What about destructors, are they always called, or is this another
>> optimization if the struct is in it's default .init state?
>
> In any case, there should be 1 destructor call for every object you
> declared.
>
> Except for thing on the heap. Those are just collected, not destroyed :/

The destructor is always called. There is never a instance that gets 
destroyed without the destructor beeing called. It can happen however 
that the destructor gets called on a .init state. This happens for 
example if you use "std.algorithm.move". To be fully correct your struct 
should handle the .init state in the destructor (or assert at least so 
you can find and fix those occurences).

Kind Regards
Benjamin Thaut


More information about the Digitalmars-d-learn mailing list