Soft Clear Cache
A gentle VRAM reset that rides along in your workflow
- any
- any
Long ComfyUI workflows are memory pigs. You load a model, sample, load a second model, sample again, and by the time you hit the third stage your VRAM is a museum of dead tensors and the next run either crawls or OOMs. "Soft Clear Cache" is the node you drop into the workflow to clear that out at a chosen moment - and it passes your data through untouched, so it can sit on the wire without doing anything to your images.
What it is
NNSoftClearCache is a resource-management utility in the NN/util category of the bandifiu/ComfyUI-NN-custom-nodes pack. The README is clear about the intent: "Releases unused ComfyUI resources by unloading models, clearing GPU cache, and running garbage collection. Useful for long workflows or when managing limited VRAM." It's a passthrough node that does housekeeping as a side effect.
How it works
The mechanism is three deliberate steps, each independently toggleable:
unload_models- calls ComfyUI'sunload_all_models(), which frees the loaded checkpoints/LoRAs/VAEs from VRAM so the next model load starts from a clean slate.clear_cache- callssoft_empty_cache(), ComfyUI's "return cached GPU memory to the allocator but don't throw anything away that's actively in use" call. It's soft, hence the name - it doesn't hard-flush the CUDA cache, it just returns what's unused.- garbage collection - a Python
gc.collect()to reclaim reference cycles that reference counting misses.
Then it hands the any input straight back out the other side. That passthrough is the design trick: it means you can wire the node into your graph on the data path - say, between two heavy stages - so the cleanup happens at exactly the right moment, without needing a separate side-branch.
The inputs
any- any type, passed through unchanged. This is your data taxi; you wire whatever you want carried to the next stage.unload_models- default on. Unload loaded models from VRAM.clear_cache- default on. Soft-clear the GPU cache.
Single any output, bit-for-bit the input.
When to reach for it
The canonical use is a multi-model pipeline where stage two loads a different model than stage one - e.g. a generation stage followed by an upscale-model stage, or a face-detailer pass on a tight-VRAM card. Place NNSoftClearCache at the boundary and let it unload stage one's model before stage two loads. It's also handy as a manual "reset" you can trigger mid-iteration when you've noticed VRAM creeping up run over run.
Two honest caveats. First, unload_all_models is a blunt instrument: it unloads everything, so anything you're caching for reuse across runs (a big model you want to keep warm) gets evicted too - that can make a workflow slower if you unload a model you're about to use again. Second, because it's a passthrough, it only runs when the workflow actually executes that point of the graph - if the branch feeding it is bypassed or cached, the cleanup doesn't fire. If you want unconditional cleanup, a non-passthrough unload node is the different tool.
Installing
Part of bandifiu/ComfyUI-NN-custom-nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/bandifiu/ComfyUI-NN-custom-nodes
Restart ComfyUI (or Manager → "NN-custom-nodes"). Deps: torch, numpy, pillow - nothing extra. GPL-3.0, V3 backend API.
The behavioral trap is the same one that trips people on every unload node: unloading a model frees VRAM but makes the next load of that model slower (it has to be read from disk again). Use it when VRAM is the binding constraint, not as a routine habit. On a card with headroom, the soft cache clear alone (leave unload_models off) is usually the gentler, sufficient fix.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| any | * | — | |
| unload_models | BOOLEAN | true | — |
| clear_cache | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| any | * | — |