In the following simplified code, are the pipe.stats automatically deallocated when a new pipe is created?
package main
var pipe = &Pipe{}
type Stat struct {
Counter int
}
type Pipe struct {
stats []Stat
}
func (p *Pipe) DoSomething() {
p.stats[0].Counter++
}
func NewPipe(n int) *Pipe {
pipe = &Pipe{}
pipe.stats = make([]Stat, n)
return pipe
}
func main() {
var myPipe *Pipe
for n := 1; n <= 4; n++ {
myPipe = NewPipe(n)
myPipe.DoSomething()
}
// serve....
}
This is an existing code, with the global variable doubled in main etc. – I just want to check if memory use will accumulate over time
I would expect this gets garbage collected but not sure