Nodes/ComfyUI-MemoryManagement/Memory Cleanup 🧹
ComfyUI Node

Memory Cleanup 🧹

The manual 'do something about it' button

By kaaskoek232Β·Created about a year agoΒ·Updated 3 months agoΒ· 7
Memory Cleanup 🧹
    • cleanup_report
    • objects_collected
    • memory_freed
    • success
    β—„trigger0β–Ί
    β—„aggressive_cleanupfalseβ–Ί
    β—„include_vramtrueβ–Ί

    The simplest node in the ComfyUI-MemoryManagement pack, and the one that teaches you how the pack thinks. Memory Cleanup is a manual "run the garbage collector now" button. No background thread, no leak forensics, no thresholds - you bump a trigger, it runs a gc.collect() pass, optionally also clears VRAM, and hands you a report on what it collected and freed.

    It's the manual version of the auto nodes in the same pack. When Auto Memory Cleanup feels like overkill and you just want to force a cleanup pass before a heavy step, this is the one.

    The inputs that matter

    All three are required, and two of them are trivial:

    • trigger (INT) - change this number to fire the cleanup. It's your button.
    • aggressive_cleanup (BOOLEAN, default false) - when true it runs a more forceful GC pass.
    • include_vram (BOOLEAN, default true) - also clears the CUDA cache and runs ComfyUI's cache cleaning alongside the RAM GC. Leave it on unless you specifically don't want the GPU touched.

    Outputs

    cleanup_report (STRING) is the human-readable rundown of what happened. The interesting ones: objects_collected (INT) - the raw count of Python objects the garbage collector reclaimed - and memory_freed (INT, bytes) - how much memory that freed. success (BOOLEAN) confirms it ran. All four are for reading; there's no wiring value unless you're logging.

    Installing it

    Zero models, zero heavy dependencies - the pack's requirements.txt is just psutil plus torch, and torch ships with ComfyUI. ComfyUI Manager β†’ search "Memory Management" β†’ install β†’ restart, or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kaaskoek232/ComfyUI-MemoryManagement
    pip install -r ComfyUI-MemoryManagement/requirements.txt
    

    Heads up: the README's "Quick Deployment" block gives a broken clone URL (ComfyUI/ComfyUI-MemoryManagement, which doesn't exist). Use the kaaskoek232 one above.

    Common issues & honest advice

    • It doesn't fix real leaks. Python's GC only reclaims objects that are genuinely unreachable. If ComfyUI is growing over time - the classic long-session RAM creep - the culprit is usually references or caches the GC can't see, and this node won't touch those. That's what the pack's MemoryLeakDetector is for.
    • Don't expect dramatic memory_freed numbers. Between the allocator holding onto freed blocks and ComfyUI's own caches, the number is often smaller than you'd hope. If you see a big number, great; if not, the memory wasn't collectable anyway.
    • Firing it mid-generation is pointless - the GC runs when you bump the trigger, so it's a "between runs" tool, same as the rest of this pack.

    It's the entry-level node of the pack, and honestly that's its appeal: no config, no risk, and if you're the type who likes watching objects_collected spike before a big upscale, it's mildly satisfying. For actual prevention, go up the ladder to Auto Memory Cleanup or Smart Memory Manager.

    CategoryMemory Management

    Inputs (3)

    NameTypeDefaultDescription
    triggerINT00–1000000β€”
    aggressive_cleanupBOOLEANfalseβ€”
    include_vramBOOLEANtrueβ€”

    Outputs (4)

    NameTypeDescription
    cleanup_reportSTRINGβ€”
    objects_collectedINTβ€”
    memory_freedINTβ€”
    successBOOLEANβ€”