mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-08-14 14:56:40 +08:00
Fix memory leak by properly detaching model finalizer
When unloading models in load_models_gpu(), the model finalizer was not being explicitly detached, leading to a memory leak. This caused linear memory consumption increase over time as models are repeatedly loaded and unloaded. This change prevents orphaned finalizer references from accumulating in memory during model switching operations.
This commit is contained in:
parent
27bc181c49
commit
5a0ab8f214
@ -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):
|
if loaded_model.model.is_clone(current_loaded_models[i].model):
|
||||||
to_unload = [i] + to_unload
|
to_unload = [i] + to_unload
|
||||||
for i in 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 = {}
|
total_memory_required = {}
|
||||||
for loaded_model in models_to_load:
|
for loaded_model in models_to_load:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user