Last Updated: June 6, 2026
CPU profiling identifies which function is slow. Memory profiling identifies which code is allocating, holding, or leaking objects. The two questions are different and the tools are different. A program with a steady 4 GB memory footprint where 400 MB was expected is wasting memory somewhere, and the only way to find the leak is to measure. This lesson covers tracemalloc (built-in snapshots and diffs), memory_profiler (line-by-line and time-series), objgraph (tracking down what is holding references), and the workflows that turn vague "memory is growing" reports into concrete fixes.