[Issue 2834] Struct Destructors are not called by the GC, but called on explicit delete.

Max Samukha spambox at d-coding.com
Mon Nov 22 00:20:29 PST 2010


On 11/21/2010 08:20 PM, Sean Kelly wrote:
> <d-bugmail at puremagic.com>  wrote:
>> http://d.puremagic.com/issues/show_bug.cgi?id=2834
>>
>>
>> Max Samukha<samukha at voliacable.com>  changed:
>>
>>             What    |Removed                     |Added
>> ----------------------------------------------------------------------------
>>                   CC|
>> |samukha at voliacable.com
>>
>>
>> --- Comment #8 from Max Samukha<samukha at voliacable.com>  2010-11-18
>> 03:39:17 PST ---
>> So what is the verdict? Should we simply specify that struct
>> destructors are
>> not automatically called except in RAII and remove the struct-in-class
>> special
>> case?
>>
>> BTW, there are other problems (serious IMO):
>>
>> auto ss = new S[10];
>> ss.length = 5;
>> delete ss;
>>
>> Destructors are not called on the last 5 elements.
>>
>> ----
>> auto ss = new S[10];
>> ss ~= ss;
>> delete ss;
>>
>> We have a nasty problem when destructors are called on the appended
>> elements
>> because postblits was not run for them during append.
>>
>> etc
>>
>> Essentially, operations on arrays of structs with postblits/dtors
>> defined are
>> currently unusable.
>
> I think this is unavoidable. Consider:
>
> auto a = new T[5];
> auto b = a[4..5];
> a.length = 4;
>
> We can't safely destroy a[4] because it's aliased. Also, since there's
> no concept of an owner reference vs an alias, modifying the length of b
> could screw up a as well.
>
> For this and other reasons I'm inclined to withdraw this issue, and
> declare that since structs are value types they won't be automatically
> destroyed when collected by the GC or when held in arrays.

I agree that correct automatic struct destruction is impossible without 
significant changes to arrays/slices/GC.




More information about the Digitalmars-d-bugs mailing list