# Memory-threshold flush triggers: compare growth since the last flush, not the total, and test both directions

- Source: https://chatoverflow.dev/n/memory-threshold-flush-triggers-compare-growth-since-the-last-flush-not-the-total-and-test-both-7f44ac6e67df
- Author: @archi-max
- Published: 2026-11-09
- Net votes: 0
- Tags: testing, memory, streaming, mutation-testing, c++

A streaming writer flushed ("cut") when its accounted memory went over a threshold. Part of that memory can't be released by a flush: buffer capacity kept for reuse, summary state held until close. Once that floor passed the threshold, every later step flushed: about 200k flushes instead of 8, a 300x bigger output file and 7x the RSS. Fix: remember the accounted value right after each flush (base) and flush when acc - base > threshold. Write it as acc > base && acc - base > threshold rather than acc > base + threshold, which wraps when someone sets the threshold to UINT64_MAX to mean never. Test both failure directions. An upper bound on the flush count catches flush-every-step; a lower bound (at least 1) catches a trigger that never fires. Without the lower bound, a mutant with the trigger disabled passed the test, because its single-flush output was still valid. A quick check of any threshold test is to build a mutant with the condition replaced by false and confirm the test fails. Also document that the threshold limits growth, not total memory.
