Nodes/comfyui-memory-manager/🧹 Force Cleanup
ComfyUI Node

🧹 Force Cleanup

The only node in this pack that does exactly what its label says

By darshd9941·Created 4 months ago·Updated 4 months ago· 1
🧹 Force Cleanup
  • trigger
  • status
aggressivefalse

Of the five nodes in comfyui-memory-manager, this is the one that actually does what it says. Drop it into a workflow, and when it runs it forces Python's garbage collector, tells PyTorch's CUDA allocator to give its cached-but-unused blocks back to the driver, and syncs the GPU so the numbers are honest afterwards. The README's example workflow tells you where it belongs:

[Load Checkpoint] → [Force Cleanup] → [Load LoRA] → [KSampler]

Between two model-heavy stages - checkpoint then LoRA, base then refiner, image then upscaler - is exactly where the slack builds up and exactly where this node clears it. It's the same idea as the popular "Clean Vram" node in ComfyUI-Easy-Use, minus the rest of a 200-node pack.

What it does, precisely

Reading the source, cleanup() is refreshingly short:

  1. Snapshot VRAM before.
  2. gc.collect() to free Python-side objects whose tensors are holding CUDA memory.
  3. torch.cuda.empty_cache() to release unused cached blocks back to the driver.
  4. torch.cuda.synchronize() so pending kernel work finishes before you measure.
  5. Snapshot after, and report the difference as "Freed XMB VRAM" or "No memory freed".

The aggressive toggle (a BOOLEAN, default off) runs gc.collect() three times and then cleans again - a bit more thorough for stubborn reference cycles, at a small time cost. Honestly, the default is usually enough.

Here's the boundary you need to respect: it does not unload models. empty_cache only reclaims allocator slack - blocks PyTorch is holding but not using. Your loaded checkpoint stays resident in VRAM. If you want models actually off the card, that's ComfyUI's own Edit → Unload Models and Execution Cache menu item (or its keybinding), which is the stronger tool for a hard reset.

Inputs and output

  • trigger (any type): optional. Wire a previous node into it to make the cleanup fire at a controlled point instead of whenever the queue happens to reach it.
  • aggressive (BOOLEAN, default false): the only setting you'll touch. Flip it on when a single pass isn't recovering what you expect.
  • Output: status (STRING). It reports how much was freed - nothing else to wire, it's a fire-and-forget node.

A small reassurance: getting "No memory freed" is normal and not a bug. If the allocator had no cached slack at that moment, there's genuinely nothing to reclaim - empty_cache is not a defrag tool.

Installation

Part of the comfyui-memory-manager pack, same install as its siblings:

cd ComfyUI/custom_nodes
git clone https://github.com/darshd9941/comfyui-memory-manager.git
cd comfyui-memory-manager
pip install -r requirements.txt   # torch>=2.0, which you already have

Or via ComfyUI Manager - search comfyui-memory-manager, install, restart. No model files, no extra dependencies.

Troubleshooting

  • Node missing from the menu after install: restart ComfyUI. Custom nodes register on startup.
  • It frees nothing before a big model load: that's expected - cleanups don't unload models. Pair it with the built-in Unload Models and Execution Cache when you need a real reset.
  • The status string isn't visible: it's a STRING output; feed it into a text-display node if you want it on the canvas.

And the community-caution, because it's earned: people who stack memory-management nodes everywhere often find ComfyUI's own management does less work as a result. Use this node where you actually see the hump, not as a nervous tic on every connection.

Categorymemory/management

Inputs (2)

NameTypeDefaultDescription
triggeropt*
aggressiveoptBOOLEANfalse

Outputs (1)

NameTypeDescription
statusSTRING