[SDL] ot - memory leaks

neil at cloudsprinter.com neil at cloudsprinter.com
Fri Aug 3 02:03:22 PDT 2007


Quoting Jacek Poplawski <jacekpoplawski at gmail.com>:

> 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.
>


but if it's inside a function i can only access it from that function, my
(probably worng) understanding was that anything created in a function was
killed at the end of that fucntion, or is that java?




More information about the SDL mailing list