Nodes/ComfyUI-JDCN/LogicUtil_Memory String
ComfyUI Node

LogicUtil_Memory String

Remember a value between runs — the flip-flop that saves your batch

By daxcay·Created 2 years ago·Updated about a year ago· 159
LogicUtil_Memory String
  • input1
  • flag
  • *

Most ComfyUI nodes are stateless: run them twice and they forget everything. LogicUtil_Memory String is the exception that's actually useful - it holds onto a value so the next queue run can see it. The docs in the code call it "flip-flop behaviour," which is exactly right: one input stores, one input latches, and the output keeps returning the stored value until you tell it to update.

How it works

Mechanically it's small. input1 is the value you want to remember (typed *, default empty). flag decides whether to update the stored value - if flag is truthy, the node overwrites its memory with input1; if flag is falsy, it just returns whatever it remembered last time. Two subtleties you'll trip over:

  • First run always stores. The internal memory starts as None, so on the very first execution it grabs input1 regardless of flag. The flag only matters from the second run onward.
  • Memory is per node instance, in RAM. It survives across queue runs in the same ComfyUI session, but it does not survive a ComfyUI restart, and duplicate copies of the node have separate memories. Close the app and the slate is clean.

The classic pattern: a "previous value" holder. Feed the last generated prompt or strength into input1, keep flag low, and the output is what the previous run used - perfect for "only regenerate if this changed" logic, or for building a difference between consecutive iterations in an animation loop. Drive flag from a comparator and you've got a conditional latch: update memory only when some condition fires, otherwise keep serving the old value.

It's named "Memory String" but the * input type means it'll happily hold numbers and other values too - the name undersells it. Like the whole LogicUtil family, this is a port of aria1th's ComfyUI-LogicUtils riding inside the JDCN pack, whose README documents the file and latent batch nodes and never gets around to these. When you see LogicUtil_Memory String in a graph, that's the original class name with the pack prefix.

Install

Install is the standard JDCN routine: ComfyUI Manager → "Install Custom Node" → search JDCN → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/daxcay/ComfyUI-JDCN
cd ComfyUI-JDCN && pip install -r requirements.txt

Only piexif on the requirements list, no models to fetch. And the most common "it's broken" report with this node is actually just someone restarting ComfyUI mid-batch and wondering why the memory reset - it didn't break, it forgot. That's the documented behavior.

CategoryLogicUtil

Inputs (2)

NameTypeDefaultDescription
input1*
flag*0

Outputs (1)

NameTypeDescription
**