Thread overview
[Issue 21550] core.memory.__delete does not actually work
Jan 15, 2021
Adam D. Ruppe
May 27, 2021
Dlang Bot
May 28, 2021
Dlang Bot
January 15, 2021
https://issues.dlang.org/show_bug.cgi?id=21550

--- Comment #1 from Adam D. Ruppe <destructionator@gmail.com> ---
BTW also this page: https://dlang.org/deprecate.html#delete says to call GC.free instead. This is incorrect as GC.free(arr.ptr) is a do-nothing operation. You MUST get the base of the block.

I'm slightly concerned that the block might be shared with some other array.... is there ever a case where two small `new` allocated arrays would ever share a GC block? Of course I know other slices can use it, but that's expected, I'm just concerned about surprising action at a distance.

If that never happens, just doing GC.free(GC.addrOf(ptr)) I believe is an
acceptable fix in both __Delete's impl and in that documentation page's
suggestion.

--
January 15, 2021
https://issues.dlang.org/show_bug.cgi?id=21550

Steven Schveighoffer <schveiguy@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@gmail.com

--- Comment #2 from Steven Schveighoffer <schveiguy@gmail.com> ---
To clarify, a new array will be pointing at the front of the block unless the array size is large enough to be in an extendable block. Last I checked, that was 2k bytes.

The reason is simple: array size is stored at the end of small blocks for alignment. But an extendable block can have the block size change from one call to the next. To avoid issues with that happening, the array size is stored at the front of the block, pushing the array off by some number of bytes. This leads to arr.ptr not pointing at the front of the block.

The fix is also simple -- use the info.base just like the original.

--
May 27, 2021
https://issues.dlang.org/show_bug.cgi?id=21550

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
@adamdruppe created dlang/druntime pull request #3481 "Fix issue 21550" fixing this issue:

- Fix issue 21550

https://github.com/dlang/druntime/pull/3481

--
May 28, 2021
https://issues.dlang.org/show_bug.cgi?id=21550

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/druntime pull request #3481 "Fix issue 21550" was merged into master:

- 471cbd14c11c15be31b48373cd794f94656b439a by Adam D. Ruppe:
  Fix issue 21550

https://github.com/dlang/druntime/pull/3481

--