ZML_清理内存显存
Nuke the VRAM between runs without restarting ComfyUI
- 任意数据
- 输出
ComfyUI has a way of slowly strangling itself over a long session: model stays loaded, cached tensors pile up, and by the fifth workflow the thing that used to run in 6GB now OOMs at 9. ZML_MemoryCleaner is the "flush it all" button you can drop into the graph - a node whose entire job is to unload models, force garbage collection, and clear the CUDA cache.
The README positions it plainly in the 2026.03 update: "添加了个清理显存和内存的节点." It's a maintenance node, not a fancy one. Which is fine - maintenance is exactly what long ComfyUI sessions need.
What it actually does
Two independent switches:
- 清理显存 (default on) - the heavy one. It calls
comfy.model_management.unload_all_models()to drop everything from VRAM, runsgc.collect(), thensoft_empty_cache()to release the CUDA cache. This is the standard "give me my VRAM back" sequence ComfyUI itself uses, just packaged as a node. - 清理内存 (default off) - system RAM. This one's platform-specific and a little more aggressive: on Windows it calls into
kernel32/psapito empty process working sets and trim the system file cache; on Linux it runsmalloc_trimand (with root) writes to/proc/sys/vm/drop_caches. It's the kind of thing that can help on machines where the OS is holding freed pages, but it's not magic - and on Linux without root, the drop_caches part just silently fails (the code catches the error and moves on).
There's also an optional 任意数据 input that passes straight through to the 输出 output. That's a deliberate design choice: it lets you insert the cleaner inline in a chain - the data flows through it while the cleanup happens - so the node doesn't force you to rewire your graph just to add a memory flush at a specific point in the pipeline.
When to use it
The honest answer: more than you think you need to. The classic pattern is at the end of a memory-hungry branch - after a big upscale, a batch render, or before a model swap - so the next branch starts clean instead of inheriting the last one's footprint. It's also the right node to wire in when you're chaining multiple model families (SDXL → FLUX → video) in one session and ComfyUI isn't releasing memory between them.
The caveat: unloads cost time. Every unload_all_models() means the next sampler has to re-load the model from disk, so dropping this node between every single step will make a long workflow noticeably slower. Use it at the seams - the places where you'd otherwise be reaching for a restart.
Install
Ships in ComfyUI-ZML-Image:
cd ComfyUI/custom_nodes
git clone https://github.com/zml-w/ComfyUI-ZML-Image
# restart ComfyUI
or ComfyUI Manager → search "ComfyUI-ZML-Image". It uses psutil (in the pack's requirements) and the ComfyUI model-management internals - nothing exotic. Chinese-first UI; translation patch at https://github.com/zml-w/ZZZ_ZML_English_Patch.
One honest warning: the Windows "empty working set" loop iterates over every running process and could nudge other apps' memory. It's low-risk and the code guards everything with try/except, but if you're running something important in parallel, maybe leave 清理内存 off and rely on 清理显存 - that's the switch that does 95% of the useful work anyway.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| 清理显存 | BOOLEAN | true | 清理GPU显存 |
| 清理内存 | BOOLEAN | false | 清理系统内存 |
| 任意数据opt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| 输出 | * | — |