Destructor called while object is still alive

Daniel N no at public.email
Fri Oct 23 07:39:37 UTC 2020


On Friday, 23 October 2020 at 07:32:02 UTC, Ola Fosheim Grøstad 
wrote:
> On Friday, 23 October 2020 at 06:15:32 UTC, frame wrote:
>> Not sure if this is expected behaviour, but I find this weird:
>> The destructor is called on the object just because it gets 
>> out of scope?
>
> The destructor may not be called at all by the GC, or it might 
> be called whenever there is no pointer found in 
> memory/registers. Since D is essentially using C-style 
> code-gen/optimizers that has little to no knowledge of a GC it 
> may be called prematurely or never.
>

Simple fix:
auto foo = Bar.create();
=>
scope foo = Bar.create();



More information about the Digitalmars-d mailing list