March 22, 2017
On Wednesday, 22 March 2017 at 08:57:34 UTC, ANtlord wrote:
> On Wednesday, 22 March 2017 at 06:47:26 UTC, Ali Çehreli wrote:
>> On 03/21/2017 09:57 PM, ANtlord wrote:
>> > Thank you for clarification. But I have one more question. Do
>> I have to
>> > use destroy for deallocating object from stack?
>>
>> Yes because what is going out of scope are two things:
>>
>> - A buffer
>> - A MyClass reference
>>
>
> Oh I got it. I have to use `destroy` in this case. If I use `scope` I haven't buffer and MyClass reference then I can don't use `destroy`. Do I understand correctly?

You still have the buffer (the class has to go somewhere!), but it is implicit (you can't refer to it directly only through the class reference) and so is the destructor call, as opposed to the emplace + explicit buffer combo. In the latter case the class destructor will not be called automatically so you must do it yourself with `destroy`.

March 23, 2017
On Wednesday, 22 March 2017 at 13:19:32 UTC, Nicholas Wilson wrote:
> On Wednesday, 22 March 2017 at 08:57:34 UTC, ANtlord wrote:

> You still have the buffer (the class has to go somewhere!), but it is implicit (you can't refer to it directly only through the class reference) and so is the destructor call, as opposed to the emplace + explicit buffer combo. In the latter case the class destructor will not be called automatically so you must do it yourself with `destroy`.

My bad. It appears I need to clarify. I mean the case that I create object without delaying. I mean simple construction.

scope myObj = MyClass(1);

Answering own question:
In this case object is allocated using stack (according documention https://wiki.dlang.org/Memory_Management#Allocating_Class_Instances_On_The_Stack). Function `destroy` used for cleanup object from heap (according documention https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation).
1 2
Next ›   Last »