More radical ideas about gc and reference counting

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sat May 3 20:44:28 PDT 2014


On Sat, 03 May 2014 22:44:39 -0400
Nick Sabalausky via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> On 5/3/2014 6:44 PM, Andrei Alexandrescu wrote:
> > On 5/3/14, 12:40 PM, Walter Bright wrote:
> >> On 5/1/2014 7:59 AM, Andrei Alexandrescu wrote:
> >>> If a class has at least one member with a
> >>> destructor, the compiler might need to generate a destructor for
> >>> the class.
> >>
> >> And in fact that's what dmd does.
> >
> > Which suggests a simple solution for calling destructors for
> > structs and arrays:
> >
> > * Lower new for structs to return:
> >
> > new S;
> > ->
> > return &(new class { S member; }).member;
> >
> > * Lower array construction similarly.
> >
> > Then voila, the anonymous classes will destroy structs and arrays
> > appropriately.
> >
>
> Uhh, but doesn't this completely break as soon as class dtors go away?

Based on other comments, I think that Andrei has been convinced that class
destructors can't go away at this point and that there certainly isn't any
consensus that it would even be desirable for them to go away (though what
he'd choose to do if we could break code willy-nilly, I don't know). So,
this particular proposal is presumably done with the idea that class
destructors are here to stay. Rather, it's trying to make it so that the
destructors for structs on the heap get run unlike now - which is a much
better direction to try and go IMHO.

- Jonathan M Davis


More information about the Digitalmars-d mailing list