delete and __delete not equivalent

Adam D. Ruppe destructionator at gmail.com
Fri Jan 15 13:59:21 UTC 2021


On Friday, 15 January 2021 at 13:15:12 UTC, Nick Treleaven wrote:
> From that issue, it's surprising that delete frees array memory 
> even when the ptr field isn't the start of the allocation.

while(true) {
   int[] a = new int[](whatever);
   delete a;
}

That will not run out of memory. Change it to `__delete(a);` or 
`GC.free(a.ptr)` like the docs tell you to do and it will.

It is true that if you slice a and delete it, it still blasts the 
whole block which might be surprising.... but like plain simple 
new/delete pair actually working certainly isn't surprising and 
plain simple new/__delete pair doing absolutely nothing makes the 
whole thing pretty worthless. Hence the bug report.


More information about the Digitalmars-d mailing list