I'm having an argument with a friend, over possible wasted resources in Go.
Does a Reader have to be closed, if it's operating over an in-memory byte array?
func readJar(zipBytes []byte, readMeta bool) (m jar.Manifest, err error) {
reader, err := zip.NewReader(bytes.NewReader(zipBytes), int64(len(zipBytes)))
if err != nil {
return
}
for _, file := range reader.File {
switch file.Name {
case jar.ManifestPath:
m, err = readManifest(file)
if err != nil {
return
}
}
}
return
}
func readManifest(file *zip.File) (jar.Manifest, error) {
reader, err := file.Open()
if err != nil {
return nil, err
}
defer reader.Close()
return jar.ReadManifest(reader)
}
Whilst originally it was thought to be a source of File Handle Leaks, something else got the blame.
Will this leak memory, or does Go have sufficient escape analysis / garbage collection that it will be fine?