A few considerations on garbage collection
Orvid King via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 30 09:04:15 PDT 2014
On Wednesday, 30 April 2014 at 15:33:29 UTC, Andrei Alexandrescu
wrote:
> 4. Currently, struct objects created with new do NOT have their
> destructors called during collection. I think this may
> continue, meaning that structs created with new are somewhat
> low-level and are meant to be destroyed and deallocated
> manually.
>
> 5. This brings up arrays of structs. As far as I understand,
> destructors will never be called for these, even after all
> references are gone:
>
> struct S { ~this() { ... } }
> auto a = new S[100];
>
> Unlike (4), arrays of structs are high-level and frequently
> used. I think we must do something about it, so I plan to
> support calling destructors for arrays of structs.
Although it would be a breaking change, I am intending to propose
that the destructors of heap-allocated structs be handled in the
same way as destructors of classes in my GC implementation. I am
also intending to propose a guarantee that, if the program exits
normally, all destructors will be invoked before the application
ends. To help facilitate this I intend to have a thread dedicated
to calling destructors. I'm still working on typing out the
entire design of the GC, but I don't currently see a reason
(design-wise) why I'd have to change these things.
More information about the Digitalmars-d
mailing list