Program crash: GC destroys an object unexpectedly

Steven Schveighoffer schveiguy at gmail.com
Tue Sep 14 16:06:24 UTC 2021


On 9/14/21 10:56 AM, jfondren wrote:
> On Tuesday, 14 September 2021 at 14:40:55 UTC, eugene wrote:
>> On Tuesday, 14 September 2021 at 12:09:03 UTC, Steven Schveighoffer 
>> wrote:
>>> This project is too big and complex
>>
>> Really, "too big and complex"?
>> It's as simple as a tabouret :)
>> It's just a toy/hobby 'project'.
> 
> A 5-pound phone isn't "too heavy" for an adult to carry but it won't 
> sell well. It's not just about capabilities but what efforts people are 
> willing to expend.
> 
> I would troubleshoot your issue by gradually making it @safe and 
> thinking about exceptions. One exception I didn't think about earlier 
> was the 'misaligned pointer' one that I said I suppressed just to find 
> the next @safe complaint:
> 
> https://dlang.org/spec/garbage.html says:
> 
>> Do not misalign pointers if those pointers may point into the GC heap,
> 
> So even if the lifetimes of your EventSource structs are fixed, the GC 
> can reap the object they're pointing to. You could fix this by having a 
> 128-bit struct and passing C an index into it, so to speak.

I don't think this is the problem.

The misaligned pointers are only happening within the stack frame, along 
with references to the objects stored also in another parameter. So they 
should not cause problems with the GC.

The storage of the references inside other objects is not misaligned.

-Steve


More information about the Digitalmars-d-learn mailing list