Nodes/ComfyUI_EmAySee_CustomNodes/EmAySee Cache Cleaner
ComfyUI Node

EmAySee Cache Cleaner

The mid-workflow 'did you try turning it off and on' — forcing a VRAM purge

By EmAySee·Created about a year ago·Updated 4 months ago· 2
EmAySee Cache Cleaner
  • anything
  • output

Every ComfyUI user eventually hits it: the workflow that runs for ten images fine, then dies on image eleven with an out-of-memory error because VRAM slowly filled up. EmAySee Cache Cleaner is the manual nudge for exactly that moment - a pass-through node you drop into the graph that, when executed, forcibly unloads all models, empties ComfyUI's cache, runs garbage collection, and clears the CUDA cache before passing your input through untouched.

The key word is manual. ComfyUI already manages VRAM reasonably well on its own; this node exists for when that automatic management isn't enough. The classic use is batch or loop workflows that load and reload models (video, upscaling, multi-sampler passes) where memory leaks or accumulates across iterations. Drop it between iterations, and each pass starts from a clean slate instead of a half-full one.

It's the ComfyUI equivalent of torch.cuda.empty_cache() plus ComfyUI's own unload_all_models() and soft_empty_cache() - and in fact the source (py/EmAySee_CacheCleaner.py) calls exactly those, in order, plus gc.collect() and torch.cuda.ipc_collect() on CUDA systems.

How it works

The node takes any input (* type) so it can sit anywhere in a graph, then runs this sequence when executed:

  1. comfy.model_management.unload_all_models() - kicks every model out of VRAM.
  2. comfy.model_management.soft_empty_cache() - ComfyUI's own cache clearing.
  3. gc.collect() + torch.cuda.empty_cache() + torch.cuda.ipc_collect() - Python and CUDA-level cleanup.

Then it returns the input unchanged, so it behaves as a transparent node with a side effect. That ordering matters: unload first, then clear caches, so the freed memory is actually released.

The inputs that matter

  • anything - a single wildcard input, required. Feed it whatever's flowing through your graph at that point; it's only there to force the node to execute in sequence.
  • output - the same value, passed through untouched.

There's no threshold, no "free X GB then stop" setting - it's all or nothing.

Install

Part of the EmAySee pack:

cd ComfyUI/custom_nodes
git clone https://github.com/EmAySee/ComfyUI_EmAySee_CustomNodes

Restart ComfyUI (or Manager → "ComfyUI_EmAySee_CustomNodes"). Category: EmAySee_Utils. No dependencies beyond ComfyUI's own.

Gotchas

The big one: this unloads all models, not just the ones you're done with. Put it before a node that needs a loaded checkpoint and you'll pay a full reload cost - which for a big model can be slower than the OOM you were avoiding. Place it where nothing needs the loaded models afterward, typically near the end of a loop iteration or before a heavy section. Also, aggressive cache clearing can hurt throughput in workflows that intentionally reuse cached activations; if your pipeline was fine before, this isn't a free performance pill. And the usual pack caveat: hobbyware, no guarantees, no support - though the five lines it calls are ComfyUI's own well-tested functions, so the risk here is placement, not the node itself.

CategoryEmAySee/Utils

Inputs (1)

NameTypeDefaultDescription
anything*

Outputs (1)

NameTypeDescription
output*