go1.8.5
go1.9.2
. : devel +f01b928 Sat Nov 11 06:17:48 2017 +0000
( go1.10alpha).
// Create a temporary slice containing invalid pointers.
// The idea is that the local variable slice can be garbage collected at the end of the function call.
// When the slice is scanned for linked objects, the GC comes across the invalid pointers.
A Go . , , , GC . (go1.8.5
go1.9.2
). undefined , , GC , (go devel
).
Go , GC run run GC .
var handle C.Handle
fmt.Fprintf(os.Stderr, "%[1]T %[1]v %[1]p\n", handle)
slice := make([]C.Handle, 1000000)
for i, _ := range slice {
slice[i] = C.getInvalidPointer()
}
uintptr
. ,
package main
import "unsafe"
import "C"
func getTempSlice() {
slice := make([]uintptr, 1000000)
for i, _ := range slice {
slice[i] = uintptr(unsafe.Pointer(C.getInvalidPointer()))
}
}
func main() {
getTempSlice()
}