Nodes/RES4LYF/Legacy2_SamplerOptions_GarbageCollection
ComfyUI Node Runs on cloud

Legacy2_SamplerOptions_GarbageCollection

Trade sampling speed for fewer OOM crashes

By ClownsharkBatwing·Created 2 years ago·Updated 22 days ago· 1,222
Legacy2_SamplerOptions_GarbageCollection
  • sampler
  • sampler
garbage_collectiontrue

This one's a single-purpose reliability patch: it forces Python's garbage collector to run after every sampling step, so tensors that would otherwise pile up in memory (and eventually cause an out-of-memory crash on a large model like Flux) get cleaned up as you go instead of accumulating across the whole run. RES4LYF's own description of it is blunt about the trade-off - it "can help with OOM issues during inference for large models... the tradeoff is slower sampling." That's the whole node in one sentence.

Where this fits in the pack

Notice the display name in ComfyUI: Legacy2_SamplerOptions_GarbageCollection. This is one of RES4LYF's older nodes, from before the all-in-one ClownsharKSampler consolidated most sampler tuning into one node's extra_options box. The README is explicit that these older, standalone sampler-option nodes stick around and still work - "the previous versions will remain available but with 'Legacy' prepended to their names" - they're just not the primary path anymore if you're on the newer sampler UI. If your workflow already uses ClownsharKSampler, check whether the same garbage-collection behavior is available as a text flag in its extra options box before reaching for this standalone node.

How it works, mechanically

It's a sampler-wrapping node: you feed it a SAMPLER (whatever explicit or implicit sampler you've selected elsewhere - res_2m, euler, dpmpp_2m, doesn't matter which), it patches that sampler's step function to call Python's garbage collector after each step, and hands back a SAMPLER that's a drop-in replacement in your existing setup. Nothing about your sampler choice, schedule, or noise settings changes - only what happens to memory between steps.

The inputs and outputs that matter

  • sampler (SAMPLER, required) - the sampler you want wrapped. Comes from a KSamplerSelect-style node or one of RES4LYF's own sampler-selection nodes.
  • garbage_collection (BOOLEAN, default true) - the switch. Leave it true to get the OOM-mitigation behavior; set it false and this node becomes a pure passthrough, useful if you want to A/B whether it's actually helping without deleting the node from your graph.

Output: a sampler, wired into whatever sampler input your graph expects (a SamplerCustom-style node, typically).

How to install it

Comes with the RES4LYF pack - no separate install for individual nodes. Via ComfyUI Manager: search "RES4LYF", install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ClownsharkBatwing/RES4LYF/
cd RES4LYF
pip install -r requirements.txt

Common issues & troubleshooting

You're OOMing on a large model like Flux or SD3.5 mid-generation, not at the start. That's the exact symptom this node targets - memory creeping up step by step rather than failing immediately on model load. If you're OOMing immediately when the model loads, this won't help; that's a quantization or VRAM-budget problem, not a between-steps memory leak.

Sampling got noticeably slower and you're not sure it's worth it. That's expected and stated up front by the node's own description - forcing garbage collection every step has a real time cost. Only use this when you're actually hitting OOM crashes, not as a default-on setting; on a model and resolution that already fits comfortably in VRAM, it's pure overhead with no benefit.

You want this behavior but you're using ClownsharKSampler, not standalone sampler nodes. Check its extra_options text box first - RES4LYF's newer all-in-one sampler often exposes legacy-node behaviors as flags there instead of requiring you to wire in a separate legacy node.

CategoryRES4LYF/legacy/sampler_extensions

Inputs (2)

NameTypeDefaultDescription
samplerSAMPLER
garbage_collectionBOOLEANtrue

Outputs (1)

NameTypeDescription
samplerSAMPLER