Represent each generated sequence position by an immutable head and a lazily memoized successor, and give each iterator its own pointer into the shared chain. Computing a successor invokes the privately owned generator once; lagging copies reuse that same successor. Consequently a mutable programming closure generating Fibonacci numbers can support interleaved independent cursor positions. Sharing only the generator and a copied current value would instead consume the generator's mutable state twice. This construction can retain all cells between the fastest and slowest live cursors; it does not guarantee constant memory usage.
Memory usage Created 2026-10-20 Updated 2026-11-05
An algorithm's memory usage is the storage it occupies under a specified accounting convention. Total storage can include input and output, while auxiliary space complexity counts extra working memory; recursion stacks, temporary arrays and cached results must be included when relevant. An iterative binary search needs constant auxiliary storage, but a recursive implementation can keep logarithmically many stack frames. Reporting memory without specifying whether counts bits, elements or machine words can hide a substantial difference. Peak live storage and cumulative allocated storage are also different measurements.