Read about stack and heap memory - note that the examples here are C++ not Go, but you should be able to follow them.
One important difference between these languages is that in Go, you don't need to worry about whether a value lives on the heap or the stack (in fact, Go is allowed to choose where your variable lives, and even move it around) - this means that it's ok to return a pointer to a stack variable in Go.
You also don't need to call delete yourself in Go - Go is a garbage collected language so it will delete variables when they're no longer needed.
Read about stack and heap memory - note that the examples here are C++ not Go, but you should be able to follow them. One important difference between these languages is that in Go, you don't need to worry about whether a value lives on the heap or the stack (in fact, Go is allowed to choose where your variable lives, and even move it around) - this means that it's ok to return a pointer to a stack variable in Go. You also don't need to call
delete
yourself in Go - Go is a garbage collected language so it will delete variables when they're no longer needed.