π Garbage Collector
Out of Memory? Garbage Collector Shakes ComfyUI Down for Spare RAM
- Input
- Output
If you've ever watched ComfyUI die with an out-of-memory error mid-workflow - on a 16 GB machine, that's a Tuesday - you know the feeling of staring at RAM you can't get back. GarbageCollector (π Garbage Collector, from ControlFlowUtils) is a big red button that forces ComfyUI, PyTorch, and Python to all drop what they're holding.
It's a passthrough node: anything you send in comes out the other side, only after the cleanup ran. You drop it into the middle of a workflow right before the heavy step that keeps choking.
What it actually does
The node doesn't just call gc.collect() and call it a day. Its garbage_collect() function runs a small arsenal:
- ComfyUI's own memory manager soft-empty cache
torch.cuda.empty_cache()andtorch.cuda.ipc_collect()for VRAM bookkeeping- Python's
gc.collect()for RAM - Optionally, on Windows, launches WinMemoryCleaner.exe to flush the standby list and working sets
Three inputs, all worth understanding:
- Input - the passthrough data. Required, but it can be anything, even a dummy.
- RAM - on by default. On Windows this attempts the WinMemoryCleaner step.
- Mode - how the RAM cleaning runs. Off means Wait until completion (blocks a few seconds, needs no privileges); on means Run async - fire-and-forget, but it requires ComfyUI (Python) to be running with admin rights.
Output is simply Output, your data forwarded after the sweep.
The catch most people miss
That Windows RAM-cleaning magic is not included. It only works if you've downloaded WinMemoryCleaner.exe from the IgorMundstein/WinMemoryCleaner repo and dropped it in your ComfyUI root folder. Without the exe, the RAM branch silently does nothing - the torch/python cleanup still runs, but that's it. So if you enable RAM and see no difference, check that the file is actually sitting next to ComfyUI's main.py. And the async mode genuinely requires admin privileges, or the spawn fails silently.
Where this node shines is RAM exhaustion. Long loops are the classic trigger - this pack's own Loop nodes cache every iteration in memory, so a 100-iteration loop can eat tens of GB before you notice. Putting a GarbageCollector at the top of each iteration keeps that in check. If your problem is VRAM rather than RAM, the author's own advice applies: use it in conjunction with this pack's Unload Models node, right after it, to force models off the GPU when a stage is done.
Install
GarbageCollector ships inside VykosX/ControlFlowUtils, so the install is the pack install:
# ComfyUI Manager β Install Custom Nodes β search "ControlFlowUtils"
# or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/VykosX/ControlFlowUtils
Restart and it's under πΊ VykosX-ControlFlowUtils. No model files, no Python dependencies. If you're on Linux or macOS the RAM/WinMemoryCleaner half simply isn't applicable - the torch and gc collection still works fine everywhere.
Final honest take: this node won't fix a workflow that genuinely needs more RAM than you have. It will claw back the garbage that ComfyUI and long-running loops leave lying around, and on a 16 GB machine that's often the difference between a workflow that completes and one that doesn't. For RAM-heavy loop workflows, it's arguably the most useful node in the pack.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| Input | * | Data to forward to other nodes after cleaning the memory | |
| RAM | BOOLEAN | true | Attempt to clear the RAM on Windows systems. Requires WinMemoryCleaner.exe to be placed in the ComfyUI root folder |
| Mode | BOOLEAN | false | Specifies whether to wait for memory cleaning to succeed before continuing |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| Output | * | Data that will be forwarded to other nodes after cleaning the memory |