[SDL] ot - memory leaks
Peter Mackay
mackay.pete+sdl at gmail.com
Thu Aug 2 14:34:27 PDT 2007
Wikipedia is fairly helpful on this,
http://en.wikipedia.org/wiki/Memory_leak
You basically need to make sure that, whatever you create (directly or
indirectly) you clean up using the appropriate function. Otherwise it
just floats in the ether, using resources which could be used for
something else.
Common pairings:
malloc -> free
new -> delete
new[] -> delete[]
SDL_CreateX -> SDL_FreeX
glGenX -> glDeleteX
And so on.
Smart pointers go quite far in avoiding memory leaks, but require a
decent knowledge of C++ to understand.
In particular, Boost "intrusive_ptr"s can easily wrap DirectX objects
and SDL surfaces, maintaining the reference count for you.
For many objects, you can use STL containers instead of rolling your
own containers.
Hope this helps,
Peter
On 02/08/07, neil at cloudsprinter.com <neil at cloudsprinter.com> wrote:
> Quoting Sam Lantinga <slouken at devolution.com>:
>
> >
> >> i compiled my code on linux and ran it through valgrind to discover
> >> just how bas
> >> it was, i did notice some things that looked like it was sdl
> >
> > FYI, as far as I know there are no memory leaks in SDL,
>
> sorry didn't mean to diss teh SDL ;)
>
>
> i still dont really know what is the best way to deal with /aviod memory leaks
> tho..
>
> valgrind documentaion seems to tell me how the memory leak occurs but
> not how to
> plug it!!
>
> there must be something somewhere on the web that tells a dumbass like
> me where
> and what to do!
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
More information about the SDL
mailing list