ComfyUI-FreeMemory is a custom node extension for ComfyUI that provides advanced memory management capabilities within your image generation workflows. It aims to help prevent out-of-memory errors and optimize resource usage during complex operations.
ComfyUI-FreeMemory is a custom node extension for ComfyUI that provides advanced memory management capabilities within your image generation workflows. It aims to help prevent out-of-memory errors and optimize resource usage during complex operations.
Four specialized nodes for freeing memory:
Attempts to free both GPU VRAM and system RAM
Compatible with both Windows and Linux systems
Seamlessly integrates into existing ComfyUI workflows
Includes an "aggressive" mode for more thorough memory cleaning
custom_nodes
directory:
git clone https://github.com/ShmuelRonen/ComfyUI-FreeMemory.git
psutil
library:
pip install psutil
Insert these nodes at strategic points in your workflow to free up memory. This can potentially allow for larger batch sizes or more complex operations without running out of resources.
Each node includes an "aggressive" boolean input:
False
(default) for standard memory cleaning.True
for more thorough, aggressive memory cleaning.When a FreeMemory node is executed:
torch.cuda.empty_cache()
to free up CUDA memory that is no longer being used by PyTorch but hasn't been released back to the system.comfy.model_management.unload_all_models()
comfy.model_management.soft_empty_cache()
torch.cuda.empty_cache()
gc.collect()
.sync
to flush file system buffers./proc/sys/vm/drop_caches
to clear pagecache, dentries, and inodes.EmptyWorkingSet
from the Windows API to reduce the working set size of the current process.The nodes report on initial and final memory usage for both GPU VRAM and system RAM, providing visibility into the cleaning process.
Contributions to improve efficiency or expand capabilities are welcome. Please feel free to submit issues or pull requests.
For more information or support, please open an issue on the GitHub repository.