Re: atexit
- Posted by ags <eu at 531pi.co.nz> Feb 08, 2006
- 465 views
Al Getz wrote: > > How do you know what's released automatically and what isnt? > Isnt it a good habit to make sure to release anything you use? I had wondered about this myself. With SDL for example calling SDL_Quit() frees everything you've allocated, ie: SDL Library Documentation (C documentation) ------------------------------------------------------------- SDL_Quit(): Description SDL_Quit shuts down all SDL subsystems and frees the resources allocated to them. This should always be called before you exit. For the sake of simplicity you can set SDL_Quit as your atexit call, like: SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO); atexit(SDL_Quit); ------------------------------------------------------------- It doesn't say anything about "Freeing any surfaces created with SDL", which have no doubt been malloced by the dll. And I'm pretty sure there are lots of other examples out there where a call to an external C dll does a malloc(...) and has no idea that your program is about to quit. I agree with you that it is good practice to free everything you allocate and not rely on assumption or possibly incomplete or ambiguous documentation. Gary