What should happen here?
Steven Schveighoffer
schveiguy at gmail.com
Mon Sep 20 20:18:16 UTC 2021
On 9/20/21 3:20 PM, Steven Schveighoffer wrote:
>
> Then why are pointers to structs, arrays, structs containing class
> references not treated the same?
>
> I'm not sure why class references are singled out, but they are for some
> reason.
If I change the struct initialization to a function it has the same
behavior.
e.g.:
```d
struct S {
~this() { writeln("dtor"); }
}
auto makes() { return new S; }
void main()
{
auto s = makes();
GC.collect();
GC.collect();
writeln("end of main");
}
```
Also shows option 2.
So it has something to do with how the return value is stored.
-Steve
More information about the Digitalmars-d
mailing list