Memory Cleaner (Force)
The Windows RAM sledgehammer that can free 40GB in one pass
- anything
- output
The name is "Memory Cleaner (Force)" and the "Force" is doing real work. ComfyUI already manages VRAM on its own - models get evicted and reloaded on demand, and that's usually enough for image generation. This node exists for a different pain: Windows system RAM that quietly inflates to 50-60GB when you chain heavy models (Flux, Wan, video workflows), or a batch loop that OOMs after five iterations no matter what you do. If you're on Windows with a lot of RAM and big workloads, that's the itch it scratches. If you're on Linux, macOS, or mostly SDXL, read the caveats below before you bother.
What actually happens when you run it
It's a 7-step pipeline, and it's more thorough than most "free memory" nodes:
- Force-unloads every ComfyUI model using ComfyUI's own
model_managementhooks -unload_all_models(),soft_empty_cache(),cleanup_models(), plus afree_memory()call that asks for 100GB just to force aggressive eviction. - Three
gc.collect()passes to grab unreferenced Python objects. - Clears the PyTorch/CUDA cache -
torch.cuda.empty_cache(), IPC collect, reset peak stats. - The step that makes the headline numbers: Windows API calls via
ctypes-EmptyWorkingSetandSetProcessWorkingSetSize(-1, -1), which shove your process's working set out to the pagefile, plus_heapmin()to shrink the C runtime heap. - CUDA sync, a final GC pass, and optionally a Windows standby-list purge (needs admin).
If the in-process WinAPI calls fail (no admin privileges, err 6), it spawns ram_trim_target.py --pid <you> as a separate process to do the trim - the README claims a 95%+ success rate and shows ~40GB freed this way.
Here's the honest part you need before you get excited: that 30-45GB number is working-set trimming, not memory that stops existing. The OS moves those pages to pagefile.sys - they're free again in the "available" sense, but you've spent disk space to get there, and the pages get paged back in if the process touches them. It's a real win when Windows is choking on a bloated working set, not a license to pretend physics changed.
Inputs that matter
- aggressive_trim (default True) - the master switch for the OS-level step. Off = just GC + CUDA cache (1-2GB).
- skip_trim_if_c_low (True) and min_c_free_gb (20.0) - your safety pair. OS trim grows the pagefile, so if C: has less than
min_c_free_gbfree, it skips the trim rather than filling your disk. The README recommends bumpingmin_c_free_gbto 60 for heavy workloads. Keep the skip guard on. - external_helper (True) - enables the separate-process fallback. Leave it on; it's the difference between "freed 2GB" and "freed 40GB".
- purge_standby (False) - the admin-only standby list purge. Ignore unless you run ComfyUI as administrator.
- anything → output - it's a pass-through: wire any data flow through it so the cleanup sits inline without breaking your graph.
Install
ComfyUI Manager: search ComfyUI-MemoryCleaner. Or the old-fashioned way:
cd ComfyUI/custom_nodes
git clone https://github.com/eddyhhlure1Eddy/ComfyUI-MemoryCleaner
then restart ComfyUI. Dependencies are just psutil and torch (you already have torch); no model downloads, no heavy deps. The pack is new and niche - a single maintainer, barely any community footprint - so it's worth a quick skim of nodes.py before you trust it; custom nodes run arbitrary code, and "memory cleaner" is exactly the kind of pack a suspicious person checks. The good news: the whole thing is a few hundred lines, mostly ctypes calls, easy to audit.
Common gotchas
- C: drive keeps losing 30-40GB after cleanup. That's the pagefile growing - the expected cost of OS trim. Raise
min_c_free_gbor move your pagefile to another drive. - "Process RAM freed: 0.000 GB". Check the console: either the C: guard skipped the trim ("Skipping OS trim: C:\ free ... < ..."), privileges failed, or models were still loaded so there was nothing to unload. The external helper fallback usually kicks in for the privilege case.
- Linux/macOS are nearly a no-op for the big step - the code does
malloc_trim(0)on Linux and nothing on macOS. You get the GC + torch cache bits (a couple GB) and that's it. This is genuinely a Windows tool.
Use it where it earns its keep: after a heavy model finishes, at the end of each batch-loop iteration, or before switching to a second heavy model. Don't put it after every node - it force-unloads all models, so the next model load pays a reload penalty. That's the trade for the big cleanup, and it's the thing people forget.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| aggressive_trimopt | BOOLEAN | true | — |
| enable_privilegesopt | BOOLEAN | true | — |
| purge_standbyopt | BOOLEAN | false | — |
| external_helperopt | BOOLEAN | true | — |
| skip_trim_if_c_lowopt | BOOLEAN | true | — |
| min_c_free_gbopt | FLOAT | 200–200 | — |
| anythingopt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| output | * | — |