In Go, I have some http responses and I sometimes forget to call:
resp.Body.Close()
What happens in this case? will there be a memory leak
See https://golang.org/src/net/http/client.go
"When err is nil, resp always contains a non-nil resp.Body."
but they do not say when err != nil, resp always is nil. They go on to say:
"If resp.Body is not closed, the Client's underlying RoundTripper (typically Transport) may not be able to re-use a persistent TCP connection to the server for a subsequent "keep-alive" request."
So I have typically solved the issue like this:
client := http.DefaultClient
resp, err := client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return nil, err
}