To create a profile of memory allocations, you can invoke ‘mprof’ with the ‘-m’ (‘--profile memory-words’) option. This will profile the amount of memory allocated, measured in units of words. (A word is 4 bytes on a 32-bit architecture, and 8 bytes on a 64-bit architecture.)
Alternatively, you can use ‘mprof’'s ‘-M’ (‘--profile memory-cells’) option. This will profile memory in units of “cells”. A cell is a group of words allocated together in a single allocation, to hold a single object. Selecting this option this will therefore profile the number of memory allocations, while ignoring the size of each memory allocation.
With memory profiling, just as with time profiling, you can use the ‘-c’ (‘--call-graph’) option to display call graph profiles in addition to flat profiles.
When invoked with the ‘-m’ option, ‘mprof’ only reports allocations, not deallocations (garbage collection). It can tell you how much memory was allocated by each procedure, but it won't tell you how long the memory was live for, or how much of that memory was garbage-collected. This is also true for ‘mdprof’.
The memory retention profiling tool described in the next section can tell you which memory cells remain on the heap.