Trackalloc - a lightweight heap profiler
by Travis McLeskey (travis -at- mcleskey -dot- org)
News | Description | Trackalloc vs. the (many) alternatives | Download
- May 25th, 2004 - Trackalloc 1.0a released (initial release)
Trackalloc wraps the ISO C memory functions with functions that keep records of current allocations. These records can be written to files at selected
points in the program under test. The files can then be summarized using the
included generate_stats.pl script. Output from this script looks a little like
this:
size of outstanding allocations made at addHashEntry.c:70 (malloc):
125664 | *
| ****
| ***
| ***
| * **
| *** **
| *** ***
106368 |**
|------------------
0 50
Trackalloc is especially useful for seeing where and when your program is using and leaking memory.
Pros:
- It lets you quickly and visually assess trends in your program's memory usage
- It lets you dump the current allocations at a specific point in your program or periodically, instead of just on program exit
- It breaks down outstanding allocations by filename and line number where they were made
- It is threadsafe (using pthreads), but the threading code can be disabled at compile time
- It is very portable and compatible, since it does not use platform-specific features and does not affect memory function calls in linked-in code
- It warns about bad frees under normal use
- The speed penalty is small
- It works with JNI (that's why it was originally written)
Cons:
- It is C-only
- You must include trackalloc.h in your source files
- Your program must be recompiled
- There is no detection of bad reads or writes
Copyright (c) 2004 Travis McLeskey