Structs returned by pointers

Are SDL_Surface structs, SDL_VideoInfo structs and anything else returned by
pointer via SDL function calls automatically cleaned up by SDL afterwards
inside SDL_Quit, or should I be calling delete/free on these pointers (I
assume free since SDL is written in C)? I’ve just started using SDL so I
haven’t had a chance to dig into the source or detect memory leaks with my
software.

Thanks,
Jeff_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar ? get it now!
http://toolbar.msn.com/go/onm00200415ave/direct/01/

Jeff Schiller wrote:

Are SDL_Surface structs, SDL_VideoInfo structs and anything else
returned by pointer via SDL function calls automatically cleaned up by
SDL afterwards inside SDL_Quit, or should I be calling delete/free on
these pointers (I assume free since SDL is written in C)? I’ve just
started using SDL so I haven’t had a chance to dig into the source or
detect memory leaks with my software.

Most SDL structures are automatically freed by SDL.
Those that are not have an SDL function to free them, which must be used instead of delete or free().

As for surfaces, things are slightly trickier - you should call SDL_FreeSurface() on all of them except for the screen.

Chris E.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040425/571db886/attachment.pgp

Are SDL_Surface structs, SDL_VideoInfo structs and anything else returned by
pointer via SDL function calls automatically cleaned up by SDL afterwards
inside SDL_Quit, or should I be calling delete/free on these pointers (I
assume free since SDL is written in C)? I’ve just started using SDL so I
haven’t had a chance to dig into the source or detect memory leaks with my
software.

You need to read the documentation for each function that returns a
value. While it isn’t always clear… they do give you hints about what
to do with the pointers returned by SDL functions.

For example: the documentation for SDL_SetVideoMode() states that the
structure will be cleaned up by SDL_Quit(). Other structures are
mentioned to be “read only” that usually means that they are actually
static structures that don’t need to be cleaned up.

Another example are the create surface functions. Those functions have a
related function named SDL_FreeSurface() that you must use to free a
surface. In general, if a structure returned by an SDL function needs to
be cleaned up by the programmer there is a “free” function provided for
the task. Those free functions understand the internal details of the
structure and are needed to do a complete cleanup that just calling
free() would not do.

I understand the frustration you are facing, a lot of information in the
documentation is not spelled out as explicitly as it could be. But, if
you read it carefully it is there. :slight_smile:

	Bob PendletonOn Sat, 2004-04-24 at 15:52, Jeff Schiller wrote:

Thanks,
Jeff


FREE pop-up blocking with the new MSN Toolbar get it now!
http://toolbar.msn.com/go/onm00200415ave/direct/01/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

±--------------------------------------+