Calling destroy on struct pointer

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Feb 25 00:36:02 PST 2017


On 02/25/2017 12:17 AM, Radu wrote:

 > destroy(cc) -> does c = C.init
 > destroy(*cc); -> calls the C dtor
 >
 > Is this by design? If so - how can I destroy and get the dtor called
 > without dereferencing the pointer?

It's by design because setting a pointer to null can be considered as 
destroying the pointer. Dereferencing is the right way of destroying the 
object through the pointer.

I had added the following warning after somebody else was burnt by this 
feature. :)

   http://ddili.org/ders/d.en/memory.html#ix_memory.destroy

Ali



More information about the Digitalmars-d-learn mailing list