Debugging Memory Problems with MemoryScape : Chapter 1 Locating Memory Problems : Batch Scripting and Using the CLI : Using the -dheap Command : Detecting Leaks: dheap -leaks
Detecting Leaks: dheap -leaks
The dheap -leaks command locates memory blocks that your program allocated and are no longer refe enced. It then displays a report that describes these blocks; for example:
d1.<> dheap -leaks
process 1 (32188): total count 9, total bytes 450
* leak 1 -- total count 9 (100.00%), total bytes 450 (100%)
-- smallest / largest / average leak: 10 / 90 / 50
: malloc PC=0x40021739 [/.../malloc_wrappers_dlopn.c]
: main PC=0x0804851e [/.../local_leak.cxx]
: __libc_start_main PC=0x40055647 [/lib/i686/libc.so.6]
: _start PC=0x080483f1 [/.../local_leak]
If you use the -check_interior option, MemoryScape considers a block as being referenced if a pointer exists to memory inside the block.
In addition to providing backtrace information, the CLI:
*Consolidates leaks made by one program statement into one leak report. For example, leak 1 has nine instances.
*Reports the amount of memory consumed for a group of leaks. It also tells you what percentage of leaked memory this one group of memory is using.
*Indicates the smallest and largest leak size, as well as telling you what the average leak size is for a group.
You might want to paint a memory block when it is deallocated so that you can recognize that the data pointed to is out-of-date. Tagging the block so that you can be notified when it is deallocated is another way to locate the source of problems.