title: http.Response.Body copying leads to large memory usage increase
body: <p>So I'm trying to get the response body out of http.Response, to do some manipulation, and then set it back. This is my first attempt at getting it out without draining the http.Response:</p>
  
  <pre><code>bodyBytes, err := ioutil.ReadAll(resp.Body)
  if err != nil {
      // err
  } else {
      cachedBody := string(bodyBytes)
  
      // Restore the io.ReadCloser to its original state
      // This is causing huge increases in memory usage.
      resp.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
  }
  </code></pre>
  
  <p>If I send 500 requests through, with a 1mb response size (a large piece of JSON, but it could be any format, not only JSON), the server memory usage goes up to ~400mb, and doesn't come back down. Is this normal? Is there something wrong with the above code? Am I missing something to release the memory?</p>
  
  <p>defer resp.Body.Close() has no effect.</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>Edit 1</p>
  
  <p>Here's a gist with a simple version of the proxy, including the suggested close call. If the server at localhost:3000 (where it's proxying to) returns a large response, memory usage will quickly increase. In my case, I'm returning a 1mb json file, and sending 500 requests through the go proxy increases memory usage to around 400mb.</p>
  
  <p>The go proxy:<br>
  <a href="https://gist.github.com/marbemac/300c4c376171cbd27cc3" rel="nofollow">https://gist.github.com/marbemac/300c4c376171cbd27cc3</a></p>
  
  <p>A simple node server that returns a file in the same directory called large_response.json.<br>
  <a href="https://gist.github.com/marbemac/55aaa78f5858484d33f6" rel="nofollow">https://gist.github.com/marbemac/55aaa78f5858484d33f6</a></p>