What should happen here?
Ali Çehreli
acehreli at yahoo.com
Tue Sep 21 16:57:52 UTC 2021
On 9/20/21 11:55 AM, Paul Backus wrote:
>> auto c = new C;
>> foreach(i; 0 .. 10000) GC.collect;
>> writeln("end of main");
>> Option 2:
>> ```
>> dtor
>> end of main
>> ```
> Option 2 at first seems like it should be invalid, but since `c` is
> never accessed after initialization, the compiler is free to remove the
> initialization as a dead store,
Your explanation at first :) seems invalid because it seems to disregard
side-effects in the constructor the destructor. However, because
destructors for GC objects are not guaranteed to be executed anyway,
only the constructor should be considered here.
I love the overwritten register story but I think this is a bug because
"local storage" should be sufficient to keep the object alive. However,
given the presence of KeepAlive from other languages, perhaps this is a
concept that needs to be communicated better.
Ali
More information about the Digitalmars-d
mailing list