Destructor order

Andrea Fontana via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 18 07:58:47 PDT 2016


On Friday, 18 March 2016 at 14:53:20 UTC, Steven Schveighoffer 
wrote:
> On 3/18/16 7:44 AM, Nicholas Wilson wrote:
>> On Friday, 18 March 2016 at 10:20:40 UTC, Temtaime wrote:
>>> Hi !
>>> I wonder if i can rely on this code :
>>>
>>> http://dpaste.dzfl.pl/745cc5b1cdfb
>>>
>>> There's two questions:
>>> 1) Is dtors always called in reverse order ?
>> yes
>>> 2) Is all the dtors always called when i call destroy ?
>> yes. destroy calls __dtor() which recursively call __dtor() on 
>> its members
>
> I think technically not true. If you call __dtor directly, it 
> does not recurse. But this is an implementation detail.
>
> -Steve

Why doesn't this print ~B ~A?
http://dpaste.dzfl.pl/0bef0a4316b7

It raises a bug on my code because dtor are called in "wrong" 
order.
b holds a ref to a, why a is desctructed before b?

Andrea


More information about the Digitalmars-d-learn mailing list