What should happen here?
jfondren
julian.fondren at gmail.com
Sat Sep 25 23:14:54 UTC 2021
On Saturday, 25 September 2021 at 22:19:30 UTC, Walter Bright
wrote:
> Maybe the real problem is the user is expecting the destructor
> to run at a specific point in the execution.
In the case that spawned this thread, the problem was a segfault
after a hidden reference was restored to the collected object,
and the coder was certain the object should still be alive
because the scope of its auto variable hadn't ended yet. The
destructor by this point just had some debugging output so that
we could see it was being collected before the end of it scope.
The hidden reference was hidden by Linux's epoll facility, which
keeps 64 bits of arbitrary user data in kernel space, and returns
it on an event. A bit like writing a pointer address to a file
and then reading it back later.
(There's *also* meaningful work that must happen at a specific
time in destructors in this code base, and other problems. It's
pretty elaborate code by someone new to D.)
I don't think this is a problem with D, but I shared the
intuition that this object should still be alive after the point
the GC collected it, and that wrong intuition made
troubleshooting this case a lot harder.
More information about the Digitalmars-d
mailing list