Program crash: GC destroys an object unexpectedly

Steven Schveighoffer schveiguy at gmail.com
Thu Sep 23 15:53:37 UTC 2021


On 9/23/21 10:55 AM, eugene wrote:
> On Thursday, 23 September 2021 at 14:31:34 UTC, jfondren wrote:
>> Nice. I thought of GC.addRoot several times but I was distracted by 
>> the general solution of using object lifetimes with it, so that a 
>> struct's destructor would call GC.removeRoot. For your case just 
>> pinning these and forgetting about them is the easiest way to do it.
> 
> Yes, these two must live until the end of main().
> Moreover, in real (C) programs I (usually) do
> not create state machines on the fly,
> instead I keep them in pools, like RX/TX machines pools
> in echo-server and in echo-client.
> 

Technically, they should live past the end of main, because it's still 
possible to receive signals then.

But the chances of someone hitting ctrl-c in that window are quite small.

-Steve


More information about the Digitalmars-d-learn mailing list