digitalmars.D - SDL_Quit after GC shutdown?
- Ivan Trombley (8/8) Dec 27 2017 I believe that I should call SDL_Quit before my program
- Mike Parker (14/22) Dec 28 2017 No. GC cleanup happens after static destructors are run.
I believe that I should call SDL_Quit before my program terminates. However, some objects may be holding on to SDL resources and freeing these resources (particularly truetype resources) causes crashiness if SDL_Quit is called before. Is there a way to have SDL_Quit (and TTF_Quit) called after the GC has completed shutting down on program exit? If not then it could make things very complex and messy to keep track of these resources.
Dec 27 2017
On Thursday, 28 December 2017 at 06:34:00 UTC, Ivan Trombley wrote:I believe that I should call SDL_Quit before my program terminates. However, some objects may be holding on to SDL resources and freeing these resources (particularly truetype resources) causes crashiness if SDL_Quit is called before. Is there a way to have SDL_Quit (and TTF_Quit) called after the GC has completed shutting down on program exit?No. GC cleanup happens after static destructors are run.If not then it could make things very complex and messy to keep track of these resources.You really, really, really shouldn't be depending on class destructors to free resources like that. There is no guarantee a class destructor will ever be called and they are non-deterministic, so you can never ensure they will be called in a non-problematic sequence. There are a number of alternatives here. The one I recommend is to use structs to wrap your SDL resources. It's what I settled on long ago and works well for me. Yes, you will have to take a couple of extra steps to cover all your bases if you don't want to manually release things, but it's possible to keep it simple and avoid messiness.
Dec 28 2017