Free Memory (Latent)
A checkpoint flush between sampling stages
- latent
- LATENT
Latents are where a lot of workflows quietly run out of headroom - a base KSampler pass, straight into a hires-fix upscale, straight into another sampler, all while the checkpoint from the first pass is still sitting in VRAM. Free Memory (Latent) is the node for that exact seam: drop it between two latent-heavy stages and it clears memory before the next stage claims it, instead of hoping ComfyUI's automatic eviction gets there in time.
What it does
Same pattern as the rest of this pack (it ships alongside Model, CLIP, Image, and String versions): a typed pass-through that runs a memory cleanup as a side effect and hands the identical data back out. Your LATENT isn't modified - the node just clears the memory sitting around it at that point in the graph.
Standard mode is torch.cuda.empty_cache() for VRAM plus a Python gc.collect() for system RAM - releases memory PyTorch has reserved but isn't using, cheap and reversible. Turn aggressive on and it adds comfy.model_management.unload_all_models() and a soft cache empty before the CUDA clear, which drops every loaded model, not just whatever produced this latent. On Linux, aggressive mode also flushes pagecache and dentries (may need elevated privileges to fully work); on Windows it trims the process's working set via the Win32 API. Both modes log memory before and after so you can see what actually got reclaimed.
The inputs and outputs that matter
latent- theLATENTyou're routing through. Required, and it's the reason to use this node at all.aggressive- boolean, defaults toFalse. Standard mode clears unused CUDA cache only; aggressive unloads everything currently loaded and does a harder reset.
Output is a single LATENT, identical to the one you passed in. Wire it into whatever's next - a VAE Decode, an upscale/hires-fix sampler, another KSampler in a chain.
Installing it
Via ComfyUI Manager: search ComfyUI-FreeMemory, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ShmuelRonen/ComfyUI-FreeMemory
pip install psutil
Restart ComfyUI. psutil is the one dependency, no model files involved, and cloning the repo installs all five FreeMemory nodes together.
Where people get burned
The trap here is the same one that shows up across low-VRAM tooling generally: aggressive mode is a blunt instrument. It doesn't distinguish "unload whatever produced this latent" from "unload everything ComfyUI has cached" - it's the latter, always. If your VRAM already fits your workflow, bolting an aggressive Free Memory (Latent) node into every hires-fix chain by reflex means the next stage pays a full reload cost, which frequently costs more time than it saves. Save aggressive mode for the moments you're actually watching VRAM climb toward the ceiling - multi-pass upscale chains on a card that's genuinely tight, or a batch loop generating many latents back to back where memory would otherwise accumulate.
It's also worth being honest about what this node can't do: it clears caches, it doesn't patch a real leak. If memory keeps climbing run over run despite this node being wired in, something upstream - usually a custom node not releasing its tensors - is the actual problem, and no downstream cache-empty fixes that. And since this reaches into comfy.model_management internals rather than ComfyUI's public API, a core update that changes those internal functions can break the node outright; that's the risk you accept with any pack calling into memory-management internals directly, not something specific to a bad install.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| latent | LATENT | — | |
| aggressive | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |