More radical ideas about gc and reference counting

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri May 2 14:44:47 PDT 2014


On Fri, 02 May 2014 21:03:15 +0000
monarch_dodra via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> On Friday, 2 May 2014 at 15:06:59 UTC, Andrei Alexandrescu wrote:
> > So now it looks like dynamic arrays also can't contain structs
> > with destructors :o). -- Andrei
>
> Well, that's always been the case, and even worst, since in a
> dynamic array, destructor are guaranteed to *never* be run.
> Furthermore, given the "append causes relocation which
> duplicates", you are almost *guaranteed* to leak your
> destructors. You just can't keep track of the usage of a "naked"
> dynamic array.
>
> This usually comes as a great surprise to users in ".learn". It's
> also the reason why using "File[]" never ends well...

Heck, I probably knew that before, but I had completely forgotten. If you'd
asked me yesterday whether struct destructors were run in dynamic arrays,
I'd have said yes. And if someone like me doesn't remember that, would you
expect the average D programmer to? The current situation is just plain
bug-prone.

Honestly, I really think that we need to figure out how to make it so that
struct destructors are guaranteed to be run so long as the memory that
they're in is collected. Without that, having destructors in structs
anywhere other than directly on the stack is pretty much broken.

- Jonathan M Davis


More information about the Digitalmars-d mailing list