Nodes/ComfyUI-MemoryManagement/Memory Leak Detector πŸ”
ComfyUI Node

Memory Leak Detector πŸ”

The forensic tool you only run when something's wrong

By kaaskoek232Β·Created about a year agoΒ·Updated 3 months agoΒ· 7
Memory Leak Detector πŸ”
    • action_result
    • leak_report
    • leak_count
    • leaks_detected
    • recommendations
    β—„actionTake Snapshotβ–Ί
    β—„snapshot_labelSnapshotβ–Ί
    β—„leak_threshold_mb100β–Ί
    β—„auto_snapshot_interval60β–Ί
    β—„enable_auto_snapshotsfalseβ–Ί

    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:

    1. Start Tracking - kicks off tracemalloc and records a baseline.
    2. Take Snapshot - captures the current allocation state and labels it with snapshot_label.
    3. Detect Leaks - compares the two most recent snapshots and reports anything that grew past your threshold.
    4. Stop Tracking - ends the session.
    5. 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. tracemalloc tracks 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.

    CategoryMemory Management

    Inputs (5)

    NameTypeDefaultDescription
    actionCOMBOTake Snapshot5 options: Start Tracking, Take Snapshot, Detect Leaks, Stop Tracking, Get Report
    snapshot_labelSTRINGSnapshotβ€”
    leak_threshold_mboptFLOAT10010–1000β€”
    auto_snapshot_intervaloptFLOAT6010–600β€”
    enable_auto_snapshotsoptBOOLEANfalseβ€”

    Outputs (5)

    NameTypeDescription
    action_resultSTRINGβ€”
    leak_reportSTRINGβ€”
    leak_countINTβ€”
    leaks_detectedBOOLEANβ€”
    recommendationsSTRINGβ€”