Hello guys,
I have a very strange problem with freeing the memory taken by surfaces in SDL. I have a program in Linux C which is displaying different information screens - every single function is a another screen, the main() function only fires the desired function.
One of the functions:
Code:
void showMessageE1() {
SDL_Surface *message1 = NULL;
SDL_Surface *message2 = NULL;
font = TTF_OpenFont("/etc/sterd_gui/assets/font.ttf", 32);
SDL_FillRect(screen, &clipRect, 0xFF);
SDL_UpdateRect(screen, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
SDL_Rect offset1, offset2;
offset1.x = 20;
offset1.y = 95;
offset2.x = 29;
offset2.y = 135;
message1 = TTF_RenderUTF8_Shaded(font, "BLA BLA BLA", redColor, whiteColor);
message2 = TTF_RenderUTF8_Shaded(font, "IMPORTANT MESSAGE", redColor, whiteColor);
SDL_BlitSurface(message1, NULL, screen, &offset1);
SDL_BlitSurface(message2, NULL, screen, &offset2);
SDL_Flip(screen);
SDL_FreeSurface(message1);
SDL_FreeSurface(message2);
font = NULL;
message1 = NULL;
message2 = NULL;
}
When I switch back and forth between the different screens, the memory keeps increasing (I check it with the ‘top’ command under linux).
I don’t know why the SDL_FreeSurface and NULL assignment to the specific surface, is not freeing the memory at all. Am I doing something wrong or maybe is this a kind of bug? I use also the SDL TTF library (as you can see in the code above) - maybe this is the reason why the memory keeps leaking?
Thanks in advance!