Program crash: GC destroys an object unexpectedly

eugene dee0xeed at gmail.com
Tue Sep 14 12:42:51 UTC 2021


On Tuesday, 14 September 2021 at 12:09:03 UTC, Steven 
Schveighoffer wrote:
> Though as I have learned helping C converts before, most of the 
> time things like this have to do with forgetting to store a GC 
> reference somewhere.

Yeah, in my first version I had

```d
     foreach (k; 0 .. nConnections) {
         auto sm = new EchoClient(rxPool, txPool);
         sm.run();
     }
```

instead of

```d
     EchoClient[] wrkMachines;
     foreach (k; 0 .. nConnections) {
         auto sm = new EchoClient(rxPool, txPool);
         wrkMachines ~= sm;
         sm.run();
     }
```

and even

```d
     {
         auto stopper = new Stopper();
         stopper.run();
     }
```

:)

> I still recommend pinning the object when adding the epoll 
> event and seeing if that helps.

I understand your idea, but even if this will help, the question
remains - why that particular object is so special for GC.



More information about the Digitalmars-d-learn mailing list