Re: memlacks...


Subject: Re: memlacks...
From: Paul Rohr (paul@abisource.com)
Date: Mon Mar 06 2000 - 22:38:50 CST


At 02:55 PM 3/7/00 +1100, Martin Sevior wrote:
>I'm a really old fashioned programmer who is only now realizing the
>benefits of malloc and such. I would like to know if my code causes memory
>leaks. How can I test for memory leaks via this destructor stuff?

To avoid leaks, you want to make sure that every malloc/new has a matching
free/delete. Destructors are often a very good place to put all that
cleanup logic. If the destructor for a class never fires, then you can be
sure that every instance of that class (and any memory it in turn needs to
clean up) has leaked.

To really be sure that you haven't generated any leaks usually requires a
platform-specific tool. For example, most Win32 programmers either use the
rudimentary heap-checking tools built into VC's debug C library, or they
link with another (proprietary) product called BoundsChecker. (We do the
former, so any leaks in XP or Win32 code usually get caught and plugged
fairly quickly.)

I'll let experts for each of the other platforms discuss their favorite
tools. ;-)

Paul



This archive was generated by hypermail 2b25 : Mon Mar 06 2000 - 22:33:27 CST