[Issue 14134] Free of large array does not work
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Feb 6 11:21:10 PST 2015
https://issues.dlang.org/show_bug.cgi?id=14134
--- Comment #6 from Steven Schveighoffer <schveiguy at yahoo.com> ---
(In reply to Rainer Schuetze from comment #5)
> Maybe we should relax the restriction on base pointers for free().
>
> What should happen with code like this?
>
> struct S { ~this() { printf("~this\n"); } int x; }
>
> S[] arr = new S[1000];
> S[] slice = arr[100..200];
> S[] tail = arr[200..1000];
> delete slice;
>
> Should it call call only 100 destructors? All 1000? Is this invalid code?
Good question. I would tend to think that there are several right answers:
1. Destroy entire array.
2. Destroy only the slice, do not run dtors on the head or tail
3. Error, must delete entire array
4. Do nothing (and don't free the array).
Wrong thing to do would be run destructor on slice and run it again when the
memory is freed.
My preference is for option 3, but that may be too heavy handed.
--
More information about the Digitalmars-d-bugs
mailing list