[SDL] ot - memory leaks

Jacek Poplawski jacekpoplawski at gmail.com
Fri Aug 3 01:59:16 PDT 2007


On 8/3/07, neil at cloudsprinter.com <neil at cloudsprinter.com> wrote:
>
> ok, i get this, one thing i'm not too sure about is, in some of my
> fucntions i
> create surfaces for the game as and when needed, for this the function
> uses 5
> surfaces which i SDL_Surface *surface at the start of the function, i
> then free
> 4 of these but one needs to be returned, what happens then? i cant free
> the
> surface before it returns otherwise it will return nothing. can i free
> it after
> i've returned it? i thought the return was the end of the function...


You should destroy the surface when you stop using it.
It can be end of the program if you can't find better place.
IMHO it's better to use C++ and allocate SDL_Surface in constructors and
destroy it in destructors.

-- 
Free Software - find interesting programs and change them
NetHack - meet interesting creatures, kill them and eat their bodies
Usenet - meet interesting people from all over the world and flame them
Decopter - unrealistic helicopter simulator, get it from
http://decopter.sf.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/private.cgi/sdl-libsdl.org/attachments/20070803/06d67e92/attachment.htm 


More information about the SDL mailing list