SI-7266 Stream leaks memory

Changed tail-generation function to mutable and clear it after it's used to allow any captured memory to be freed once the tail has been generated.

(This is a case where a by-name parameter was used when a lazy val parameter was wanted instead.  If we ever get lazy val parameters, we should switch to that.)