type A struct { a int } func gen() []*A { r := make([]*A, 1000000) for i := 0; i < len(r); i++ { r[i] = &A{i} } return r }
//var as []*A = gen() func main() { go func() { err := http.ListenAndServe(":8034", nil) if err != nil { //fmt.Printf("ListenAndServe:%s\n", err) } }() var as []*A = gen() fmt.Println(as[0]) time.Sleep(100 * time.Second) } when debug gc: 1) if the "var as []*A = gen()" is in main , the debug info is : gc 4 @2.757s 0%: 0.049+0.59+0.025 ms clock, 2.3+0/0.54/0.28+1.2 ms cpu, 16->16->0 MB, 31 MB goal, 48 P (forced) 2) if the "var as []*A = gen()" is not in main, the debug info is: gc 9 @7.172s 0%: 0.077+25+0.020 ms clock, 3.7+0/24/0.73+0.99 ms cpu, 16->16->15 MB, 31 MB goal, 48 P (forced) Anybody konw why the mark time (red numbers) is so different? go version is 1.12.7. -- 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/e3a947ed-1a42-4d17-991d-d29cc80685e0%40googlegroups.com.