Re: Finding memory leak, walking the heap?



On Wed, 20 Feb 2008 14:15:25 -0800, Ed J wrote:

How can I embed checkpoints for memory leaks in my C++ code? I'm looking
for unfreed heap space allocated with "new" but not deleted, and I would
like to be able to ask for the current allocations in my C++ code to help me
pinpoint where the leak exists.

Essentially, I'm looking for the ability to do something like this:

long bytes_allocated = heap_space_used();
... run code here that shouldn't grow the heap
if (bytes_allocated != heap_space_used())
printf( "I found a leak");

I'm using GCC 3.3.3. Unfortunately, I'm stuck with that GCC version due to
our development environment.

Thanks,
Ed Jubenville




I can also reccomend electric fence. Traps debugger when you touch it...



.



Relevant Pages

  • Finding memory leak, walking the heap?
    ... How can I embed checkpoints for memory leaks in my C++ code? ... for unfreed heap space allocated with "new" but not deleted, ... I'm using GCC 3.3.3. ...
    (comp.os.linux.development.apps)
  • Re: Finding memory leak, walking the heap?
    ... for unfreed heap space allocated with "new" but not deleted, ... I'm using GCC 3.3.3. ... our development environment. ... One word: Valgrind. ...
    (comp.os.linux.development.apps)