returning struct, destructor

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 21 11:17:49 PST 2016


On 12/21/2016 07:01 AM, Eugene Wissner wrote:

 > Isn't an optimization that changes the behavior bad? I had a crash in
 > the code where the destructor did something meaningfull, freed the
 > memory (the same pointer) twice.

Sounds like you ended up with two objects that owned the same resource. 
You can either '@disable this(this)' so that copies of this type are not 
allowed or you can handle the resource in a different way: Make a copy 
of the resource in this(this) so the two copies have their own separate 
resources, leave the resource to the GC, use reference counting, etc.

Ali



More information about the Digitalmars-d-learn mailing list