On Tue, Apr 24, 2018 at 1:12 AM, xie cui <
cuiw...@gmail.com> wrote:
>
> func foo() {
> a := new(int)
> fmt.Println(*a)
> return
> }
>
> like this ,when calling new in the function, will it be optimazed as a
> stack allaction instead of a heap allaction?
Normally, yes. For cases where it really matters you can verify this
by compiling with the -m option (go build -gcflags=-m). That will
direct the compiler to print a debugging log of escape analysis
decisions.
Ian