I've found this issue https://github.com/golang/go/issues/10303 which can answer my questions.
在 2019年3月21日星期四 UTC+8下午1:56:17,Cholerae Hu写道: > > package main > > // void a(long *p) {} > import "C" > > import ( > "unsafe" > ) > > //go:noinline > func b() { > x := int64(0) > C.a((*C.long)(unsafe.Pointer(&x))) > // do something without x > } > > func main() { > b() > } > > x should be considered unreachable after C.a . If x is something allocated > on heap, do I need to use runtime.KeepAlive(x) to make sure x will not be > garbage collected? > -- 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. For more options, visit https://groups.google.com/d/optout.