On Fri, May 21, 2021 at 7:46 AM tapi...@gmail.com <tapir....@gmail.com> wrote: > > From the outputs of the following program, > it looks the stack of a goroutine doesn't shrink immediately. > Will it shrink at some point eventually? > > > package main > > func f(i int) byte { > type T int // avoid f being inline > var a [1<<20]byte // make stack grow > return a[i] > } > > func main(){ > var x int > println(&x) // 0xc000034770 > f(100) > println(&x) // 0xc0002fff70 > > // It looks the stack hasn't shrunk here. > > f(100) > println(&x) // 0xc0002fff70 > }
Stack shrinking occurs during garbage collection, and only if the goroutine isn't doing anything and isn't sitting in a system call or a cgo call. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcV4kO0dbQ61_9WGjoLiEmRSOmm7YYn4sUTbdn_ADSfD%3DA%40mail.gmail.com.