In order to use dmalloc do the following:
for csh: alias dmalloc 'eval `\dmalloc -C \!*`', for bash: function dmalloc { eval `command dmalloc -b $*` }
On some platforms you may need to link things statically to get dmalloc to work. On Solaris this is done by linking with these options: "-Xlinker -B -Xlinker -static libraries -Xlinker -B -Xlinker -dynamic -ldl -lX11 -lXext". (You'll need to change Makefile. Thanks to Haobo Yu and Doug Smith for working this out.)
We can interpret a sample summary produced from this process on ns-2/tcl/ex/newmcast/cmcast-100.tcl with an exit statement after the 200'th duplex-link-of-interefaces statement:
Ns allocates 6MB of memory.
1MB is due to TclObject::bind
900KB is StringCreate, all in 32-byte chunks
700KB is NewVar, mostly in 24-byte chunks
Dmalloc_summarize must map function names to and from their addresses. It
often can't resolve addresses for shared libraries, so if you see lots of
memory allocated by things beginning with ``ra='', that's what it is. The
best way to avoid this problem is to build ns statically (if not all, then
as much as possible).
Dmalloc's memory allocation scheme is somewhat expensive, plus there's bookkeeping costs. Programs linked against dmalloc will consume more memory than against most standard mallocs.
Dmalloc can also diagnose other memory errors (duplicate frees, buffer overruns, etc.). See its documentation for details.