Skip to main content
gamedev.net
🔒 Locked

Lazy Foo Tutorial Question

Started by Hammonjj 0 replies 700+ views
Original Post
Hammonjj
Hammonjj
I've recently started working on SDL and I have been using Lazy Foo's tutorials to do this(They're great, by the way), but I do have a question about why he did something. Here's a link to the tutorial: http://lazyfoo.net/SDL_tutorials/lesson02/index.php He uses the SDL_FreeSurface Command to free the surface after he is done using them, but at the very end he never frees "screen" and I want to know why. Why does he need to worry about freeing both the background image and message, but not the screen? Thanks!
James HammondUniversity of ColoradoDepartment of Computer Science
rip-off
rip-off
The screen is a special surface that is freed by either SDL_Quit() or SDL_QuitSubSystem(SDL_INIT_VIDEO).

This kind of thing is mentioned in the SDL documentation, this particular point is made near the end of this page ( at the return value section ).

Actually, after reading the tutorial I see this is mentioned in it:
Quote:
Source: Lazy Foo tutorial
Now we do the end of the program clean up.

SDL_FreeSurface() is used to get rid of the surfaces we loaded since we're not using them anymore. If we don't free the memory we used, we will cause a memory leak.

Then SDL_Quit() is called to quit SDL. Then we return 0, ending the program.
You may be asking yourself "why aren't we freeing the screen surface?". Don't worry. SDL_Quit() will take care of that for us.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.