[ale] C++ Debuggery and the Path of Destruction

Geoffrey esoteric at 3times25.net
Sat Sep 25 08:41:19 EDT 2004


Bjorn Dittmer-Roche wrote:
> On Fri, 24 Sep 2004, Barry Rountree wrote:
> 
>> On Friday 24 September 2004 08:41 pm, John Mills wrote:

>> __FILE__::__LINE__ is now creating a __WHATEVER__, address 0xabcddcab
>> __FILE__::__LINE__ is now deleting a __WHATEVER__, address 0xabcddcab
> 
> 
> 
> This is handy. My trick is for each object that has a malloc or new, 
> that object is responsible for deleting/free ing the data as well. 
> Paired with a counter to keep track of mallocs in each object is handy 
> and I tend to catch memory leaks fast:

Excellent points both.  What we used to do when we were oft times 
allocating memory in many section of code is add some #ifdefs to track 
allocation and freeing.  Start the output with the memory address so 
that one can simply pipe the output to sort and should see matching 
allocations/frees:

804845c : allocated, foo.c(345)
804845c : freed, foo.c(345)

The form is:

address : [allocated|freed], __FILE__(__LINE__)

We used #ifdef because we learned that about the time you had it all 
figured out and removed the debug code, you started having another 
memory leak. :)

-- 
Until later, Geoffrey       Registered Linux User #108567
                             AT&T Certified UNIX System Programmer - 1995



More information about the Ale mailing list