Memory Leak Detector π
The forensic tool you only run when something's wrong
- action_result
- leak_report
- leak_count
- leaks_detected
- recommendations
Let's be clear about what this node is for: Memory Leak Detector is not a thing you keep in your workflow. It's the diagnostic tool you pull out when your ComfyUI session's RAM keeps growing no matter what you do, and you want to find out why before you start ripping nodes out of your graph. If you've ever watched a week-old ComfyUI install eat 20GB of RAM and restarting is your only fix, this is the difference between guessing and knowing.
It's part of the kaaskoek232/ComfyUI-MemoryManagement pack, and it's the only node in the pack built around Python's tracemalloc - the standard library's memory profiler. Everything else is about cleaning; this one is about investigating.
How it works
It's stateful, which trips people up. You drive it through the action dropdown, in sequence:
- Start Tracking - kicks off
tracemallocand records a baseline. - Take Snapshot - captures the current allocation state and labels it with
snapshot_label. - Detect Leaks - compares the two most recent snapshots and reports anything that grew past your threshold.
- Stop Tracking - ends the session.
- Get Report - dumps the analysis.
Because it's comparing snapshots, you need at least two before "Detect Leaks" has anything to compare - that's the #1 "why is nothing happening" gotcha. It also caps its own history at 100 snapshots so the detector doesn't leak itself, which is a nice touch.
The inputs that matter
- action - Start Tracking / Take Snapshot / Detect Leaks / Stop Tracking / Get Report. The whole point of the node.
- snapshot_label (STRING) - a name for the snapshot you're about to take. Use it; it makes reports readable.
- leak_threshold_mb (FLOAT, 10β1000, default 100) - a diff has to grow by this much to count as a leak. Default 100MB is reasonable for a big Python process.
- enable_auto_snapshots (BOOLEAN, default false) and auto_snapshot_interval (10β600s) - let it snapshot on a schedule so you can walk away and come back to a trend.
Outputs
action_result (STRING) confirms what just happened, leak_report (STRING) is the detailed analysis, leak_count (INT) and leaks_detected (BOOLEAN) are the headline numbers, and recommendations (STRING) tells you what to do about it. All display-only - this node isn't wiring into anything.
Installing it
No models, no heavy deps - just psutil beyond the torch ComfyUI already has. ComfyUI Manager β search "Memory Management" β install β restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/kaaskoek232/ComfyUI-MemoryManagement
pip install -r ComfyUI-MemoryManagement/requirements.txt
(That's the real URL; the README's "Quick Deployment" block points at a nonexistent ComfyUI/ComfyUI-MemoryManagement repo.)
Where it falls short - read this before you trust it
- It only sees Python.
tracemalloctracks Python object allocations. VRAM, CUDA caching, and allocations happening inside C/C++ extensions are invisible to it. The README admits this directly: "some leaks in C++ extensions may not be detected." So a "clean" report doesn't mean you're leak-free. - It's expensive. The README quotes 2β5% CPU and up to 100MB of memory while tracking is active. That's fine for a diagnosis session; it's a terrible thing to leave running permanently.
- Sequence matters. Snapshots taken before tracking starts return nothing. Start Tracking, then snapshot, then compare - the node's actions exist to force that order on you.
The best pattern: start tracking, run your workflow a few times, take a snapshot after each run, then Detect Leaks and read which file keeps growing. That filename is usually where the problem lives. When you're done, Stop Tracking - don't leave the profiler on for the fun of it.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| action | COMBO | Take Snapshot | 5 options: Start Tracking, Take Snapshot, Detect Leaks, Stop Tracking, Get Report |
| snapshot_label | STRING | Snapshot | β |
| leak_threshold_mbopt | FLOAT | 10010β1000 | β |
| auto_snapshot_intervalopt | FLOAT | 6010β600 | β |
| enable_auto_snapshotsopt | BOOLEAN | false | β |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| action_result | STRING | β |
| leak_report | STRING | β |
| leak_count | INT | β |
| leaks_detected | BOOLEAN | β |
| recommendations | STRING | β |