Model Patch Memory Cleaner
The node that unloads ModelPatchLoader patches so upscaling doesn't die
- anything
- any
If your workflow loads a controlnet-style patch via ModelPatchLoader - think Z-Image ControlNet, QwenImage BlockWise ControlNet, or SigLIP MultiFeat Proj - and then OOMs the moment you try to upscale, this is the node for you. It's a memory cleaner with a very specific appetite: the "patch model" format that ModelPatchLoader produces. The README says it twice, so I will too: this is an exceptional format, different from standard ControlNet models, and the generic cleanup nodes don't reliably get rid of it.
Like every node in this pack it's a passthrough - ANY in, ANY out. The cleanup happens between the two, and your data sails through unchanged.
What it actually does
ComfyUI tracks loaded models in current_loaded_models. The cleaner walks that list, and for every ModelPatcher instance that carries additional_models or attachments (where ModelPatchLoader parks the patch), it marks the model unused, calls model_unload() to actually drop it from VRAM, pops it out of the tracking list, and runs cleanup_models_gc() to sweep the leftovers. The upshot: the patch's weights are gone before the upscaler starts grabbing memory, instead of sitting there reserved and causing a crash you can't explain from the model sizes alone.
That last part matters. A patch can be small on disk but still pins a chunk of VRAM, and because it rides inside a ModelPatcher it can slip past ComfyUI's normal low-memory unload logic. The cleaner goes for the jugular rather than waiting for the LRU to notice.
The inputs that matter
- clear_model_patches (default True) - the whole point; do the ModelPatcher sweep described above.
- clean_gpu (default True) -
torch.cuda.empty_cache()and a sync afterward. - force_gc (default True) - one garbage-collection pass.
You'll rarely touch any of them - the defaults are the right answer for the intended workflow.
Where to put it
The README's recommended layout:
[ModelPatchLoader] → [QwenImageDiffsynthControlnet] → [Model Patch Memory Cleaner] → [Upscaling Node]
Place it after you're done with the patch and before anything memory-hungry (upscaling, a second pass). One honest caveat from the wider ecosystem: attention-level tricks and memory hacks interact badly with some of these newer models - Z-Image Base in particular is known to produce broken output with SageAttention patched in, so don't read this node as permission to stack every memory optimization on at once.
Installing it
cd ComfyUI/custom_nodes
git clone https://github.com/ussoewwin/ComfyUI-DistorchMemoryManager.git
cd ComfyUI-DistorchMemoryManager
pip install -r requirements.txt
Or via ComfyUI Manager by searching "Distorch" / "VRAM Manager". Dependencies are just torch, psutil, and nvidia-ml-py; restart ComfyUI after install and it shows up under Memory. Remember the whole pack also installs a startup NVML patch that changes ComfyUI's default VRAM headroom - that's automatic and needs no node, but it's worth knowing it's there.
Troubleshooting
The classic miss is putting the cleaner before the patch is applied - it sweeps current_loaded_models at execution time, so it must run after ModelPatchLoader has loaded the patch. If you still OOM, confirm the patch is actually the format this targets (ModelPatchLoader / ModelPatcher with additional_models), because standard ControlNet models use a different load path and this node is deliberately not aimed at them. It's a niche tool for a niche format - if you're not on a patch-model workflow, the pack's Memory Manager or Purge VRAM V2 nodes are the better general-purpose hammers.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| anything | * | — | |
| clear_model_patches | BOOLEAN | true | Clear model patches loaded via ModelPatchLoader |
| clean_gpu | BOOLEAN | true | — |
| force_gc | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| any | * | — |