Detect Memory Leaks in a Running Process with leaks
Scan a live macOS process for unreachable malloc memory using the built-in leaks command.
Run sudo leaks <pid> to scan the process for leaked memory buffers and see the number of leaks and total bytes.
01Command
Command
$ sudo leaks <pid> | head -4002What it does
leaks walks a running process's malloc heap and reports memory that is still allocated but no longer referenced by any pointer — the textbook definition of a leak. Output starts with the key summary: total leaked bytes, number of leaks, and per-allocation traces showing where each leaked buffer was created. It complements vmmap (which shows all memory, reachable or not) and works on any process, not just code you built; for Swift/Objective-C, apple's Instruments Leaks view is the friendlier alternative.
03Risk
!Warning: leaks briefly pauses the process while scanning, so it is not for production latency-critical services, and scanning requires root for other users' processes. A process that grows because of caching or fragmentation is not a leak — compare leaks output against vmmap's dirty memory before concluding.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- leaks(1) macOS man pageEvidence: Man page for leaks: searches a process's memory for leaked (unreferenced) malloc buffers and reports counts and sizes.
- Finding Memory Abuses - Apple DeveloperEvidence: Apple documentation describing using the leaks tool to detect unreachable memory in a running process.
Last verified: 2026-09-18 · Category: Developer