title: Does a Stream get Disposed when returning a File from an Action?
body: <p>I'm writing a string to a <code>MemoryStream</code> I need to return the stream to the Controller Action so I can send it off as a file for download. </p>
  
  <p>Normally, I wrap the Stream in a using statement, but, in this case, I need to return it. Does it still get Disposed after I return it? Or do I need to dispose it myself somehow? </p>
  
  <pre><code>//inside CsvOutputFormatter
  public Stream GetStream(object genericObject)
  {
      var stream = new MemoryStream();
      var writer = new StreamWriter(stream, Encoding.UTF8);
      writer.Write(_stringWriter.ToString());
      writer.Flush();
      stream.Position = 0;
      return stream;
  }
  </code></pre>
  
  <p>Controller Action that returns the file:</p>
  
  <pre><code>[HttpGet]
  [Route("/Discussion/Export")]
  public IActionResult GetDataAsCsv()
  {
      var forums = _discussionService.GetForums(_userHelper.UserId);
  
      var csvFormatter = new CsvOutputFormatter(new CsvFormatterOptions());
  
      var stream = csvFormatter.GetStream(forums);
      return File(stream, "application/octet-stream", "forums.csv");
  
      //is the stream Disposed here automatically?
  }
  </code></pre>