TryFreeMemory
Manually reclaim RAM/VRAM mid-workflow
- a
- a
Long multi-stage workflows - detect, then inpaint, then upscale, each stage its own big model - are where ComfyUI's automatic memory management starts showing its limits. It caches nodes for speed, and it doesn't always evict a model the moment you're done with it, especially inside multi-step or looping workflows. TryFreeMemory is a manual escape valve for that: a small utility node whose entire job is convincing ComfyUI to actually give memory back before you hit the next stage and run out.
How it works
It's a passthrough node: wire any value into a and the same value comes back out of a, unchanged. The reason to put it in the middle of a graph rather than off to the side is exactly that passthrough behavior - it forces the node to run after the stage whose output you fed it, and before whatever comes next, so the memory-freeing side effect happens at the right moment in the execution order.
Two independent toggles control what actually happens:
do_gc- sets a flag rather than running garbage collection immediately. Per the node's own tooltip, ComfyUI runs an automatic GC pass at the end of the run based on that flag, and the practical effect is that this node's result won't be cached. That's a trade: you get memory back, but you give up ComfyUI's "skip re-running unchanged nodes" speedup for whatever depends on it.unload_models- the immediate one. Per its tooltip, it frees models sitting in VRAM that are no longer valid or needed, and runs right when the node executes rather than waiting for end-of-run cleanup.
Inputs and outputs that matter
a(required, any type) - whatever you want to pass through while triggering the cleanup. Feed it the output of the stage you just finished with.do_gc(defaultfalse) - deferred; flags this run's result as uncacheable so end-of-run GC actually reclaims it.unload_models(defaultfalse) - immediate; frees stale models from VRAM right now.
Output: a single a, the same value, unchanged, to continue the wire into the next stage.
Installing it
ComfyUI Manager: search comfyui-easyapi-nodes. By hand:
cd ComfyUI/custom_nodes
git clone https://github.com/lldacing/comfyui-easyapi-nodes.git
cd comfyui-easyapi-nodes
pip install -r requirements.txt
Restart. TryFreeMemory doesn't need any models or extra downloads of its own.
Where people get tripped up
The two toggles solve different problems, and people often reach for the wrong one. If you're specifically fighting a VRAM ceiling - an OOM between stages because the previous model is still parked on the GPU - unload_models is the one that helps, since it's immediate; do_gc alone won't free VRAM fast enough to save you from an OOM on the very next node, because its effect is deferred to end-of-run.
The other trap is do_gc's caching cost: flip it on everywhere out of caution and you quietly lose ComfyUI's re-run caching for every downstream node that depends on this one's output, which turns "tweak one parameter and requeue" workflows into full re-runs every time. Leave do_gc off unless you've actually measured a memory problem it fixes, and place unload_models right after the stage that's hogging VRAM rather than sprinkling it everywhere defensively - it only clears models that are already stale, not ones a later node still needs, so putting it in the wrong spot in the graph does nothing useful.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| a | * | — | |
| do_gc | BOOLEAN | false | 设置垃圾回收标志,不会立即执行垃圾回收,在本次流运行结束时ComfyUI主体会根据标识自动执行一次垃圾回收(相当于不会缓存结果) |
| unload_models | BOOLEAN | false | 释放显存中已经无效的模型,会立即执行一次 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| a | * | — |