Search code examples
csdl

In SDL, do I need to free the surface I got from SDL_GetWindowSurface?


In SDL, when I destroy a window with SDL_DestroyWindow, do I also need to call SDL_FreeSurface to release the surface that is associated with that window?

SDL_Window *window = SDL_CreateWindow(/*...*/);
SDL_Surface *wsurface = SDL_GetWindowSurface(window);
/*...*/
SDL_FreeSurface(wsurface); /* <- do I also need this line? */
SDL_DestroyWindow(window);

It isn't clear to me if the surface needs to be manually released or if it gets released automatically when I destroy the window.


Solution

  • It gets released automatically. Here is the relevant documentation:

    A new surface will be created with the optimal format for the window, if necessary. This surface will be freed when the window is destroyed. Do not free this surface.