Comfy-Org / Comfy-Org/ComfyUI

RAM overflow in cycles (maybe problems with Execution Model Inversion)

Open
#4,646 5 comments 0 reactions 0 assignees View on GitHub
Potential Bug
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 6h
Merged PRs (30d)
155

Description

### Expected Behavior

I assumed that ForLoop loops do not cause RAM overflows. Or I expected to find a built-in way to controllably clear memory inside loops (inside the ForLoop body and after the ForLoop function has finished working).

### Actual Behavior

At the moment, even with simple image tools (and maybe others data, I haven't checked yet), memory overflow occurs, since RAM is not cleared of images created in a loop.
In this case, after the cycle is completed, the data is stored in memory until the current task (Queue prompt) in the queue is completed.

I used custom nodes with while/forloop functions by @guill (@BadCafeCode) from https://github.com/BadCafeCode/execution-inversion-demo-comfyui

I checked everything on the latest versions of ComfyUI and on the latest versions of custom node packages. Just a few minutes ago - the memory overflow problem exists.

Memory overflow occurs in any node that somehow works with images and modifies them.

Issue/bug for @guill

### Steps to Reproduce

As an example, I made a simple workflow in which a blur operation is performed in a loop for the same image. Over time, memory overflow occurs (if this does not happen for you, set a higher value instead of 1000 for remaining):
[Overflow_Example_Workprocess.json](https://github.com/user-attachments/files/16772151/Overflow_Example_Workprocess.json)

Screenshot of workprocess:
![image](https://github.com/user-attachments/assets/d3b2b577-6eda-482d-8cc2-db1b2670314c)

### Debug Logs

```powershell
I didn't record logs, but if necessary - you can ask me.

When memory is full, comfyui just crashes without any errors.
```

### Other

Related topics:
https://github.com/BadCafeCode/execution-inversion-demo-comfyui/issues/8
https://github.com/lquesada/ComfyUI-Inpaint-CropAndStitch/issues/32

The problem probably cannot be in custom nodes or any other nodes (including ComfyCore nodes), since they do not clean up memory by themselves during the execution of loops.

Probably, some manually controlled tool (node) for cleaning up memory in the loop, or a mechanism that will clean up memory inside the loop will be required.

P.s. Perhaps I am not aware of some features and nodes from the execution-inversion-demo-comfyui package, and perhaps there are already some ways to clear memory, but I do not know about them / did not find them in the examples.
The cleaning systems that I know do not affect the cleaning of memory with images during the loop.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.