Noob question about structs allocation

IM 3di at gm.com
Mon Oct 15 04:14:24 UTC 2018


On Monday, 15 October 2018 at 03:33:04 UTC, Basile B. wrote:
> On Monday, 15 October 2018 at 03:19:07 UTC, IM wrote:
>> I probably used to know the answer to this question, but it's 
>> been a long time since I last used D, and I don't remember. 
>> Suppose we have:
>>
>> struct S {
>>   int num;
>> }
>>
>> Would allocating an instance on the heap using:
>>
>> S* s = new S;
>>
>> use the GC, or do we have to call destroy() or delete on s 
>> ourselves?
>
> new is an operator that always allocates using the GC,
> calling destroy yourself won't hurt either but is not necessary.

What is the effect of calling destroy?
- calling the destructor?
- deallocating the memory?
- both?


More information about the Digitalmars-d-learn mailing list