On Thursday, 28 February 2019 at 04:26:47 UTC, Sam Johnson wrote:
Update: it seems that all I need to do is GC.addRoot(output); and memory leak goes away. I think I have answered my own question.
That shouldn't have any effect at all. GC.addRoot makes the GC consider that pointer to always be live. If it isn't already a GC'd pointer, the call does nothing, and if it is a GC pointer, it means it will never be collected!
Your test must be seeing something else...