[SDL] Re: TTF_RenderText functions increasing memory usage

James O\\\\\\\'Meara james at nformant.net
Fri Nov 4 22:04:59 PST 2005

As the other people have suggested, you're probably not freeing the surface. I
had the same problem with my game, and it caused a massive memory leak that
would lock it up after 2 minutes.

Here's a quick example:

textSur=TTF_RenderText_Solid(text,strOut,fontcolor);	//set the text surface
SDL_BlitSurface(textSur,NULL,screen,&r_text);		//blit text

Note: You've only got to free the surface if it's something that's going to be
constantly changing.

An example would be if you'd like to have text that displays your current score.
As your score changes, you're gonig to have to set textSur to different values,
so you have to be sure the free the surface every time.

If you were using it to always display the same unchanging text, for example "-
PAUSE -", you don't have to clear it after every screen blit, but when you're
done with the surface completely.

I hope I was clear with my answer.

More information about the SDL mailing list