Nodes/tri3d-comfyui-nodes/tri3d-clear-memory
ComfyUI Node

tri3d-clear-memory

A 'press the empty-cache button' node that passes your image straight through

By TRI3D-LC·Created 3 years ago·Updated about a year ago· 27
tri3d-clear-memory
  • input
  • IMAGE
free_mem_per_limit1.00

ComfyUI's "out of memory mid-graph" problem has a well-known blunt instrument: force a garbage-collect and empty the CUDA cache between heavy stages. tri3d-clear-memory packages that as a node you can drop into a workflow, and since a ComfyUI node has to output something, it returns the image you fed it untouched. The node is the button; the pass-through is the plumbing.

What it does

Two inputs: input (an IMAGE - required, because ComfyUI won't run a node with no inputs) and free_mem_per_limit, a float from 0 to 1, default 1. On execution it runs gc.collect(), torch.cuda.empty_cache(), torch.cuda.ipc_collect(), waits two seconds, and returns the input image unchanged.

Two honest caveats from reading the source:

  • free_mem_per_limit does nothing. It's declared, it's never read. If you're setting it expecting a "free this fraction of VRAM" behavior, you're not getting it - the node always does the same full-cache clear.
  • It clears the current process's cache, not the world's. In one ComfyUI instance it can genuinely help before a big VAE decode or a second model load. Across processes, or against actual fragmentation, it's a coin flip. It's the "have you tried turning it off and on" of VRAM, and it's occasionally exactly what you need.

The real value is placement: put it in the graph where the heavy stage ends and the next heavy stage begins, and it forces ComfyUI to actually release cached activations instead of holding them for the next run. It also gives you a convenient place to insert a pause between stages.

When to bother

If you're hitting CUDA OOM on a workflow that otherwise fits, this is a two-second experiment worth trying before you re-engineer the graph: wire your image through it between the model-heavy sections. If your workflow already fits, the node is pure overhead - two seconds of sleep per run plus a cache flush that'll just get repopulated.

Installing

ComfyUI Manager (search "tri3d"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/TRI3D-LC/tri3d-comfyui-nodes

Restart, install requirements (pip install -r custom_nodes/tri3d-comfyui-nodes/requirements.txt). Nothing to download; it's torch stdlib calls.

Troubleshooting

  • "It didn't fix my OOM" - expected sometimes; caching behavior is inconsistent. Combine with a lighter VAE or tiled decode rather than treating this as guaranteed.
  • You want the freed VRAM measured - this node prints nothing. If you need numbers, run nvidia-smi alongside.

A placebo that occasionally works is still medicine. This one is free to try, harmless to leave in, and the pass-through design means you never have to rewire anything to add it.

CategoryTRI3D

Inputs (2)

NameTypeDefaultDescription
inputIMAGE
free_mem_per_limitFLOAT1.000–1

Outputs (1)

NameTypeDescription
IMAGEIMAGE