Hard RAM/VRAM Purge (trim working set)
Kick ComfyUI's RAM hoarding out the door between long runs
- report
- rss_before_gb
- rss_after_gb
- trim_applied
After a long video generation, ComfyUI's Python process can be holding onto gigabytes of RAM it has no business keeping - cached tensors, IPC buffers, orphaned graphs. The next generation then starts from a bloated working set, pages, and feels like it's running through treacle. HardMemoryPurge is the sledgehammer for that moment: it unloads models, empties caches, runs the garbage collector, and on Windows even trims the process working set. You put it in the graph, run it once, and watch RSS drop.
It's called "hard" for a reason. This is not a gentle "soft empty cache" - it unloads all loaded models by default, so anything downstream will need to reload on the next run. Use it as a reset point between big jobs, not as a regular inline node.
How it works
It delegates to the pack's _hard_memory_cleanup routine, which does, in order:
- GPU cleanup -
unload_all_modelsunloads loaded models from VRAM;soft_empty_cachecalls the empty-cache routine. - IPC collection -
torch.cuda.ipc_collect()to reclaim cross-process CUDA buffers (ipc_collect). - GC passes - runs
gc.collect()gc_passestimes (default 3) to chase down Python cycles that single-collect misses. - Working-set trim -
trim_working_setcalls the Windows APIsEmptyWorkingSetandSetProcessWorkingSetSize(-1,-1)to actually shrink the process's committed RAM. On non-Windows this step reports itself as unavailable rather than pretending.
It measures the process RSS before and after, so you get outputs rss_before_gb, rss_after_gb, plus a report (full JSON) and trim_applied (whether the working-set trim ran). console_log mirrors the numbers to the console.
Inputs that matter
unload_all_modelsandsoft_empty_cache- both on by default. This is the full-strength version; expect reloads after.trim_working_set- the Windows-only feature; harmless elsewhere.gc_passes- 3 is fine; bump to 5 only if you see the report plateauing early.
Install
Part of IAMCCS-nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/IAMCCS/IAMCCS-nodes.git
Or ComfyUI Manager → "IAMCCS" → install → restart. No extra dependencies.
Gotchas
Two traps. First: because it unloads models, running it inside a generation loop is self-sabotage - you'll pay for reloads every iteration. Put it at a segment boundary or after a run, not mid-sampling. Second: the working-set trim is real and it works, but rss_after_gb reflects the committed working set, not necessarily a guarantee of headroom for the next run - if the next job still OOMs, the issue is VRAM fragmentation or genuinely insufficient RAM, not this node's failure. It's a hygiene tool, not a memory expansion pack.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| unload_all_models | BOOLEAN | true | — |
| soft_empty_cache | BOOLEAN | true | — |
| ipc_collect | BOOLEAN | true | — |
| trim_working_set | BOOLEAN | true | — |
| gc_passes | INT | 31–10 | — |
| console_log | BOOLEAN | true | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| report | STRING | — |
| rss_before_gb | FLOAT | — |
| rss_after_gb | FLOAT | — |
| trim_applied | BOOLEAN | — |