Created
February 18, 2024 14:03
-
-
Save gkampitakis/1ea36c7b390867e7b6dc4b078e0ca6fc to your computer and use it in GitHub Desktop.
Memory leaks in Go - Long lived references
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func readFileDetails(name string) []byte{ | |
data, err := os.ReadFile(name) | |
if err != nil { | |
return err | |
} | |
return data[5:10] | |
} | |
// not holding reference to underlying memory anymore | |
func readFileDetails(name string) []byte{ | |
data, err := os.ReadFile(name) | |
if err != nil { | |
return err | |
} | |
return bytes.Clone(data[5:10])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment