Jump to content
  • Advertisement
Sign in to follow this  

SDL_FreeSurface at end?

This topic is 4775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it necessary to free all the surfaces at the end of the program? It's not a big problem but it kinda gets annoying adding another surface to be destroyed after I create a new one. I guess I'm just lazy. Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
You need to free all the surfaces you havwe used throughout except for the screen surface which is freed by SDL_Quit(). Failing to do so will cause a resource leak as certain fields inside the structure are dynamically allocated which are only freed in the call to SDL_FreeSurface().

Share this post


Link to post
Share on other sites
If you're just exiting the program, it is a safe assumption that today's NT- and UNIX-based machines will clean up whatever crap your program allocated. I'd be a bit wary about it on older OSes (though I'm sure win9x and such work fine).

Basically, play it on the safe side. If you want to wipe them without much work, consider implementing some sort of resource-tracking system (I just stored a vector that holds all of my SDL surfaces and blow through it at the end of the game, wiping it -- not the most effective way to use it, but good enough).

Share this post


Link to post
Share on other sites
I just wrote a quick little class to do this for me.

class Image
{
public:
SDL_Surface* img;
//Constructors...

~Image()
{
SDL_FreeSurface( img );
}
};


Then you will not have to worry about it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!