[SDL] ot - memory leaks

David Olsen jolynsbass at gmail.com
Fri Aug 31 22:36:46 PDT 2007


Hi folks,
I'm very interested in a tool like this "fortify" memory manager... I 
haven't been able to get it working though, with MSVC++2005... Anyone have 
any luck at all with this setup? I am on WinXP.
Thanks,
-Dave

----- Original Message ----- 
From: "Christer Sandberg" <christer.sandberg at mdh.se>
To: "A list for developers using the SDL library. (includes SDL-announce)" 
<sdl at lists.libsdl.org>
Sent: Friday, August 03, 2007 5:15 AM
Subject: Re: [SDL] ot - memory leaks


> On Thursdayen den 2 August 2007, neil at cloudsprinter.com wrote:
>>would there be some kinda valgrind windows cygwin combination or is that
>> just too wierd and crazy?
> There is a memory debugger named Fortify
> http://www.geocities.com/SiliconValley/Horizon/8596/fortify.html
> Beside it can tell you memory leaks it's also capable to trap many memory
> violations. It's source based so you can use it on either system. Back in 
> bad
> old days when I was on DOS I used it a lot and was satisfied with it.
>
> To avoid memory leaks and memory violations you should focus on 
> documenting
> and a clean program structure. If a function returns a pointer to memory 
> that
> it has allocated, then always mention that in a comment:
> /* ... returns a pointer to a blah that the caller is responsible for... 
> */
> And similarly for members in structs:
> struct BAR {
>  /* Points to a FOO. The memory is owned by this BAR. */
>  FOO *foo;
>  /* Points to another FOO. The memory is NOT owned by this BAR. */
>  FOO *foo2;
> ...
> Also make separate functions to destroy your objects (and here you can 
> make
> use of you carefully typed comments):
> destroy_bar(BAR *bar)
> {
>  ...
>  destroy_foo(foo);
>  free(bar);
> }
>
> This way you can track where things come from and who owns them when the
> memory debugger tells you that you have a leak.
>
> Moving to C++ you basically have to do the same. Using STL may sometimes 
> help
> you, but if you put pointers into the containers you must be aware of the
> leak problem anyway. Using references instead of pointers in C++ may also
> help you, but it's not likely that you can live entirely without pointers 
> in
> C++.
> -- 
> Christer
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org 



More information about the SDL mailing list