title: Streamed ZIP file download from Rails on Heroku causes increasing memory usage
body: <p>I'm using <a href="https://github.com/fringd/zipline" rel="nofollow noreferrer">zipline</a> to generate and stream a ZIP file as a browser download. The ZIP generation and downloading happen simultaneously. Everything functions as expected but Heroku seems to use increasingly large amounts of memory as files are downloaded. The increase in memory consumption is generally close to, but not as large in size as the zip file being downloaded. The ZIP is compressed but the contents are highly compressed already so I don't think this difference is due to that. Consistently triggering a re-download of the same ZIP does repeatedly increase memory usage, but it does seem to trail off.</p>
  <p>There is no passive memory leak, but at least as far as Heroku is reporting, it's clear that something about this process requests more memory and doesn't seem to ever release it to the OS (?).</p>
  <p>Last 24 hours:</p>
  <p><a href="https://i.stack.imgur.com/VPJPC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VPJPC.png" alt="last 24 hours memory usage" /></a></p>
  <p>Last 2 hours:</p>
  <p><a href="https://i.stack.imgur.com/0Nnpc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Nnpc.png" alt="last 2 hours memory usage" /></a></p>
  <p>Ruby metrics as reported by Heroku:</p>
  <p><a href="https://i.stack.imgur.com/hQhbQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hQhbQ.png" alt="heroku ruby memory metrics" /></a></p>
  <p>Virtually every sharp increase in the memory usage graphs is a ZIP download being triggered. I changed to a dyno with 1GB memory instead of 512MB to see if it would help or release memory but it did not.</p>
  <p>Ruby free memory slots and heap objects do not seem to change at all. I don't know if this is a flaw in the beta metrics plugin on Heroku but I don't know how to investigate that.</p>
  <p>The zipline gem uses ZipTricks as a back-end, and I've re-implemented what I already had done with ZipTricks directly and found the exact same problem.</p>