Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Fix memory leak by properly detaching model finalizer (#9979)

Guy Nivc8d2117f02bc
diff --git a/comfy/model_management.py b/comfy/model_management.py
index d880f1970..c5b817b62 100644
--- a/comfy/model_management.py
+++ b/comfy/model_management.py
@@ -645,7 +645,9 @@ def load_models_gpu(models, memory_required=0, force_patch_weights=False, minimu
if loaded_model.model.is_clone(current_loaded_models[i].model):
to_unload = [i] + to_unload
for i in to_unload:
- current_loaded_models.pop(i).model.detach(unpatch_all=False)
+ model_to_unload = current_loaded_models.pop(i)
+ model_to_unload.model.detach(unpatch_all=False)
+ model_to_unload.model_finalizer.detach()
total_memory_required = {}
for loaded_model in models_to_load: