I have a structure:
type xyz struct {
x int
y string
}
func f(){
x := new(xyz) //allocating memory
}
But I cannot find any method to deallocate it in go.
- Is it not needed to deallocate it in golang?
- Is there any useful document for how memory allocation/deallocation happens in go?
new(xyz)with "allocating memory" is a dangerous assertion: There are far more ways in Go which result in an allocation. Evena:=2might allocate memory on the heap ifaescapes. Additionally: Usingnewlike that is not idiomatic; using&xyz{}is more common.