Program crash: GC destroys an object unexpectedly
Steven Schveighoffer
schveiguy at gmail.com
Thu Sep 23 15:56:16 UTC 2021
On 9/23/21 9:18 AM, eugene wrote:
> On Thursday, 23 September 2021 at 12:53:14 UTC, Steven Schveighoffer wrote:
>> We need to add a better way to do that (similar to C# KeepAlive).
>
> Do you mean some function attribute?..
>
C# KeepAlive (and Go KeepAlive) are a mechanism to do exactly what you
suggested -- use the object later.
However, they are recognized by the compiler as an intrinsic which
generates no code or side effects, but is not subject to elimination by
the optimizer.
See more details:
https://docs.microsoft.com/en-us/dotnet/api/system.gc.keepalive?view=net-5.0#remarks
-Steve
More information about the Digitalmars-d-learn
mailing list