I could just entirely skip unloading the libraries. The OS should handle that automatically when the process exits, meaning the GC should have done its final shutdown by then. I've thought about implementing such a change before, as this issue keeps cropping up around Derelict because so many people start out relying on D's destructors to release memory for them. Then again, the up side is that it highlights one of the issues of relying on destructors for this sort of thing. Another being that your SDL_Surface might never be deallocated at all until the app exits if you only rely on destructors, which could have a negative impact in a long running game. And yet another being that the GC doesn't know about the memory your SDL_Surface points to and could happily destruct your object, thereby freeing the surcface, while another pointer to it exists somewhere else in the program. Better just to use a terminate chain.
I should expand a bit. The heart of the issue in this case is
that you need precise control over the order of deallocation:
resource allocated through the shared libraries need to be
deallocated before the libraries are unloaded. Even without the
static module destructors, you can't rely on normal destructors
to do that.
- C Memory Namespace
- Re: C Memory Diggory
- Re: C Memory Namespace
- Re: C Memory Diggory
- Re: C Memory Johannes Pfau
- Re: C Memory Namespace
- Re: C Memory Johannes Pfau
- Re: C Memory Mike Parker
- Re: C Memory Mike Parker
- Re: C Memory Namespace
- Re: C Memory Namespace
- Re: C Memory Mike Parker
- Re: C Memory Mike Parker
- Re: C Memory Mike Parker
- Re: C Memory Namespace
- Re: C Memory Benjamin Thaut
- Re: C Memory Namespace