Why does logging in destructor lead to segmentation fault?
Vladimir Marchevsky
vladimmi at gmail.com
Mon Sep 11 20:26:42 UTC 2023
On Monday, 11 September 2023 at 18:08:45 UTC, Bradley Chatha
wrote:
> What's happening is that the GC is running the dtors for all
> objects after the main function's finished in a final cleanup,
> which prevents you from allocating any GC memory without
> crashing.
>
> Potentially as well the GC has already cleaned up the
> `sharedLogger` causing the null read.
What's confusing me is that debugger stops exactly on
`synchronized(mutex)` line inside of `log` implementation. Does
this operation allocate any GC memory?.. Also looking through
locals in debugger, logger object seems to be fine (otherwise it
would crash earlier, I guess?.. At least, `this` points to
something at non-zero address), `mutex` looks alive as well.
Isn't it wrong to have something garbage-collected while object
containing it is still alive?
More information about the Digitalmars-d
mailing list