ComfyUI Node

Memory Manager

Hit OOM mid-upscale? Memory Manager is a clean break in the middle of your graph

By ussoewwin·Created 10 months ago·Updated 5 days ago· 51
Memory Manager
  • anything
  • any
clean_gputrue
clean_cpufalse
force_gctrue
reset_virtual_memorytrue
restore_original_functionsfalse

ComfyUI is usually smart about juggling VRAM, but video pipelines - especially upscaling after something like WAN2.2 - have a habit of grinding to a halt with a CUDA OOM exactly when the model finally loads. This node is a controlled "breather" you drop into the middle of the graph. It runs its cleanup, then passes whatever you fed it straight through. That's the whole trick: it's a passthrough node whose output is identical to its input, and the actual job happens while the data is in transit.

It's part of the ComfyUI-DistorchMemoryManager pack (the README brands the whole thing "ComfyUI-VRAM-Manager"). One thing worth knowing up front: installing that pack already changes ComfyUI's behavior before you place a single node - it patches the VRAM headroom at startup using NVML so the browser and Discord aren't invisible VRAM thieves. Memory Manager is the manual, in-graph version of that same idea, for when you want the cleanup at a specific point in the workflow rather than relying on startup defaults.

Why you'd reach for it

The pack was built around a specific, slightly counterintuitive failure mode: OOM during video upscaling is often system RAM exhaustion, not VRAM exhaustion. ComfyUI offloads weights to RAM between stages; if your pagefile or physical RAM runs dry, the load blows up even on a 24GB card and a 64GB machine. The author's recommended pattern for video gen is to drop Memory Manager between stages, with clean_gpu, force_gc, and reset_virtual_memory all on. It's a bit like manually flushing the cache between browser tabs - crude, but it works when the automatic system doesn't.

What the inputs actually do

The node takes anything (ANY type) and returns it untouched, so wiring is trivial: previous node → Memory Manager → next node. The toggles:

  • clean_gpu - torch.cuda.empty_cache() plus a sync. Returns the reserved-but-unused pool to the driver.
  • force_gc - forces a Python garbage collection pass.
  • reset_virtual_memory - the interesting one. It calls ComfyUI's free_memory() but with an enormous request instead of zero. That matters because, as the source comments, free_memory(0, ...) is effectively a no-op - it left a Krea2 NVFP4 model resident. Asking for a huge chunk forces Comfy to genuinely unload models and empty CUDA.
  • clean_cpu - the tooltip says "use with caution," and the README is blunter: enabling it risks UI corruption. Leave it off unless you're deliberately trying to claw back RAM.
  • restore_original_functions - reverts ComfyUI's model_management to its unpatched state. You will basically never touch this.

Installing it

ComfyUI Manager is the easy path: search "Distorch" or "VRAM Manager" and install. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ussoewwin/ComfyUI-DistorchMemoryManager.git
cd ComfyUI-DistorchMemoryManager
pip install -r requirements.txt

Dependencies are light - torch, psutil, and nvidia-ml-py (the pack's install hook force-upgrades that last one for the NVML startup patch). Restart ComfyUI and the node appears under Memory.

The gotchas

This is a small, fast-moving, mostly one-maintainer pack, so treat updates with a little suspicion rather than auto-updating blindly. And when something still OOMs, remember the README's honest caveat: if the crash is during inference itself (VRAM-critical), no cleanup node is going to save you - expanding your pagefile helps the RAM-shortage case, not the VRAM case.

CategoryMemory

Inputs (6)

NameTypeDefaultDescription
anything*
clean_gpuBOOLEANtrue
clean_cpuBOOLEANfalseCPU memory cleanup (use with caution)
force_gcBOOLEANtrue
reset_virtual_memoryBOOLEANtrue
restore_original_functionsBOOLEANfalseRestore original model_management functions

Outputs (1)

NameTypeDescription
any*