Program crash: GC destroys an object unexpectedly
Steven Schveighoffer
schveiguy at gmail.com
Tue Sep 14 12:52:44 UTC 2021
On 9/14/21 8:42 AM, eugene wrote:
> On Tuesday, 14 September 2021 at 12:09:03 UTC, Steven Schveighoffer wrote:
>> 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.
>
Philosophically, it places the responsibility of making sure the object
is valid while using it on the thing that chooses to store it outside
the GC's view.
Looking at your examples, you are having to store these object
references elsewhere, surrounding seemingly innocuous and normal D usage
of objects. You have put the burden on the caller to make sure the
implementation details are sound.
But I agree that a superficial reading of your code seems like it ought
to not be collected, and that problem is also worth figuring out. I have
high confidence that it's probably not a design flaw in the GC, but
rather some misunderstanding of GC-allocated lifetimes in your code. But
that doesn't mean it's not actually a bug somewhere in D.
-Steve
More information about the Digitalmars-d-learn
mailing list