栈:存放函数的参数值,局部变量的值等

堆: 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回收

 

堆栈跟踪:

package main

import "runtime/debug"

func main() {
   slice := make([]string, 2, 4)
   Example(slice, "hello", 10)
}
func Example(slice []string, str string, i int) {
   debug.PrintStack()
}


goroutine 1 [running]:
runtime/debug.Stack(0x1, 0x0, 0x0)
	C:/Go/src/runtime/debug/stack.go:24 +0xae
runtime/debug.PrintStack()
	C:/Go/src/runtime/debug/stack.go:16 +0x29
main.Example(0xc000077f48, 0x2, 0x4, 0x4abd9e, 0x5, 0xa)
	D:/gopath/src/example/example/main.go:10 +0x27
main.main()
	D:/gopath/src/example/example/main.go:7 +0x79