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
If Response.Body won't be closed with Close() method than a resources associated with a fd won't be freed. This is a resource leak.
Response.BodyFrom response source:
It is the caller's responsibility to close Body.
So there is no finalizers bound to the object and it must be closed explicitly.
On error, any Response can be ignored. A non-nil Response with a non-nil error only occurs when CheckRedirect fails, and even then the returned Response.Body is already closed.
resp, err := http.Get("http://example.com/")
if err != nil {
// Handle error if error is non-nil
}
defer resp.Body.Close() // Close body only if response non-nil