Go version

go version go1.23.0 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/a/Library/Caches/go-build'
GOENV='/Users/a/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/a/go/pkg/mod'
GONOPROXY='xxx.com'
GONOSUMDB='xxxx.com'
GOOS='darwin'
GOPATH='/Users/a/go'
GOPRIVATE='xxxx.com'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.23.0'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/a/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/xxx/go.mod'
GOWORK='/xxx/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/mw/884f6hx53r56gd7zxsm1h8bm0000gp/T/go-build2465272456=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

go build -o ./bin/tAlloc3 ./make/tAlloc3
GODEBUG=allocfreetrace=1 ./bin/tAlloc3 &> ./tmp/2.log

my code

package main
import "fmt"
func main(){
    fmt.Println("abc")
}

What did you see happen?

nothing, only "abc"

What did you expect to see?

a lot of stack of alloc place of my code like in ./tmp/2.log

tracealloc(0xc000024000, 0x40, *runtime.p)
goroutine 0 [idle]:
runtime.mallocgc(0x40, 0x1098460, 0x1)
    /usr/local/go/src/runtime/malloc.go:1121 +0x7aa fp=0x7ff7bfeff6d8 sp=0x7ff7bfeff660 pc=0x100b9ea
runtime.makeslice(0x59960e85937f?, 0x105cbc1?, 0x1006a3f?)
    /usr/local/go/src/runtime/slice.go:103 +0x52 fp=0x7ff7bfeff700 sp=0x7ff7bfeff6d8 pc=0x1045c72
runtime.procresize(0x8)
    /usr/local/go/src/runtime/proc.go:4822 +0x15c fp=0x7ff7bfeff7b8 sp=0x7ff7bfeff700 pc=0x103d53c
runtime.schedinit()
    /usr/local/go/src/runtime/proc.go:722 +0x1d3 fp=0x7ff7bfeff810 sp=0x7ff7bfeff7b8 pc=0x1034713
runtime.rt0_go()
    /usr/local/go/src/runtime/asm_amd64.s:345 +0x11e fp=0x7ff7bfeff818 sp=0x7ff7bfeff810 pc=0x105ab3e 

**Comment From: gabyhelp**

**Related Issues and Documentation**

 - [Test report unexpected error when race detection is enabled #50323 (closed)](https://github.com/golang/go/issues/50323) <!-- score=0.87672 -->
 - [debug/pe: fatal error: runtime: out of memory on NewFile #43827](https://github.com/golang/go/issues/43827) <!-- score=0.87592 -->
 - [runtime: fatal error: sweep increased allocation count in go1.7 #16778 (closed)](https://github.com/golang/go/issues/16778) <!-- score=0.87448 -->
 - [runtime: gcstoptheworld=2 doesn't work #53885 (closed)](https://github.com/golang/go/issues/53885) <!-- score=0.87423 -->
 - [cmd/compile: stringtoslicebytetmp optimization on unescaped slice  #38501 (closed)](https://github.com/golang/go/issues/38501) <!-- score=0.87232 -->
 - [runtime: large stack makes the program hang #26154 (closed)](https://github.com/golang/go/issues/26154) <!-- score=0.87053 -->
 - [runtime: Unable to build go project on macOS 10.12 beta 4 #16575 (closed)](https://github.com/golang/go/issues/16575) <!-- score=0.87031 -->
 - [runtime: Encountering strange build stack trace when running go build #16627 (closed)](https://github.com/golang/go/issues/16627) <!-- score=0.86944 -->
 - [runtime: go1.4 "fatal error: bad pointer" #12729 (closed)](https://github.com/golang/go/issues/12729) <!-- score=0.86788 -->
 - [runtime: traceback stuck in runtime.systemstack #55851 (closed)](https://github.com/golang/go/issues/55851) <!-- score=0.86683 -->

<sub>(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in [this discussion](https://github.com/golang/go/discussions/67901).)</sub>


**Comment From: bronze1man**

Then I tried the new api from "runtime.trace" and "golang.org/x/exp/trace". I can not get stacktrace of every alloc.

package main

import ( "os" "runtime/trace" trace2 "golang.org/x/exp/trace" "fmt" )

func main(){ runTrace() f,err:=os.Open("./tmp/1.trace") if err!=nil{ panic(err) } r,err:=trace2.NewReader(f) if err!=nil{ panic(err) } for { event,err:=r.ReadEvent() if err!=nil{ fmt.Println(err) return } if event.Kind()!=trace2.EventExperimental{ continue } exp:=event.Experimental() if exp.Name=="HeapObjectAlloc"{ fmt.Println(event.String()) fmt.Println(event.Stack()) } } }

func runTrace(){ os.Setenv("GODEBUG", "traceallocfree=1") f,err:=os.Create("./tmp/1.trace") if err!=nil{ panic(err) } trace.Start(f) defer trace.Stop() toTrace() }

func toTrace(){ fmt.Println(abc) }

I can not get stacktrace of every alloc:

abc M=140704665246592 P=0 G=1 Experimental Time=98720547720960 Name=HeapObjectAlloc ArgNames=[id type] Args=[8288 10] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547721472 Name=HeapObjectAlloc ArgNames=[id type] Args=[61454 0] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547721856 Name=HeapObjectAlloc ArgNames=[id type] Args=[60426 11] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547722048 Name=HeapObjectAlloc ArgNames=[id type] Args=[61468 0] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547722624 Name=HeapObjectAlloc ArgNames=[id type] Args=[10334 12] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547723136 Name=HeapObjectAlloc ArgNames=[id type] Args=[3744 13] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547730816 Name=HeapObjectAlloc ArgNames=[id type] Args=[61482 0] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547731072 Name=HeapObjectAlloc ArgNames=[id type] Args=[8291 10] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547731264 Name=HeapObjectAlloc ArgNames=[id type] Args=[61496 0] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547731520 Name=HeapObjectAlloc ArgNames=[id type] Args=[60436 11] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547731840 Name=HeapObjectAlloc ArgNames=[id type] Args=[10336 14] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547732096 Name=HeapObjectAlloc ArgNames=[id type] Args=[3800 13] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547735616 Name=HeapObjectAlloc ArgNames=[id type] Args=[8294 15] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547735808 Name=HeapObjectAlloc ArgNames=[id type] Args=[3856 13] { 0} M=123145502023680 P=1 G=6 Experimental Time=98720547783744 Name=HeapObjectAlloc ArgNames=[id type] Args=[72704 16] { 0} M=123145502023680 P=1 G=6 Experimental Time=98720547790848 Name=HeapObjectAlloc ArgNames=[id type] Args=[73728 17] { 0} M=123145502023680 P=1 G=7 Experimental Time=98720547806720 Name=HeapObjectAlloc ArgNames=[id type] Args=[74752 16] { 0} M=123145502023680 P=1 G=7 Experimental Time=98720547807488 Name=HeapObjectAlloc ArgNames=[id type] Args=[73740 17] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547826816 Name=HeapObjectAlloc ArgNames=[id type] Args=[62608 18] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547827776 Name=HeapObjectAlloc ArgNames=[id type] Args=[60446 18] { 0} M=140704665246592 P=0 G=1 Experimental Time=98720547828800 Name=HeapObjectAlloc ArgNames=[id type] Args=[139284 18] { 0} EOF ```

Comment From: bronze1man

GODEBUG=allocfreetrace=1 is very good tool to make my code faster with less heap alloc. Now it is not working...

Comment From: MikeMitchellWebDev

runtime: remove allocfreetrace: https://go-review.googlesource.com/c/go/+/583376