SDL_FreeSurface() when surface goes out of scope

Hi all,
if I have for example this function:
void DrawImage() {
    SDL_Surface* image = SDL_LoadBMP( "image.bmp" );
    SDL_BlitSurface( image, NULL, screen, NULL );

Lets say screen is a global SDL_Surface* on which I've done SDL_SetVideoMode().
I call this function many times from main(). Do I have to SDL_FreeSurface( image )
at the end of the DrawImage() function? Or is image destroyed when it goes out of scope?
Only the pointer itself (not what it points to) will be destroyed when it goes out of scope. To free the SDL_Surface pointed to by image you have to use SDL_FreeSurface.

Loading images from file is quite slow so you probably don't want to load the image every time you draw it. It is much better to load it once and reuse it throughout your game. When you no longer need it, or you will not need it for a long time, you can free it with SDL_FreeSurface.
Ok, thanks!
Topic archived. No new replies allowed.