What should happen here?
Dukc
ajieskola at gmail.com
Tue Sep 21 09:59:11 UTC 2021
On Monday, 20 September 2021 at 18:26:59 UTC, Steven
Schveighoffer wrote:
> Without any context, what do you think should happen here?
>
> ```d
> import std.stdio;
> import core.memory;
> class C
> {
> ~this() { writeln("dtor"); }
> }
>
> void main()
> {
> auto c = new C;
> foreach(i; 0 .. 10000) GC.collect;
> writeln("end of main");
> }
> ```
>
> Option 1:
> ```
> end of main
> dtor
> ```
>
> Option 2:
> ```
> dtor
> end of main
> ```
>
> Option 3:
> ```
> end of main
> ```
>
> Option 4:
> Option 1 or 2, depending on entropy.
>
Most likely option 1. May also be option 3 though, as I remember
some warnings about trusting the GC destructor to run at all.
More information about the Digitalmars-d
mailing list