github.com/pkujhd/goloader@v0.0.0-20240411034752-1a28096bd7bd/examples/gctest/gctest.go (about) 1 package gctest 2 3 import ( 4 "fmt" 5 "runtime" 6 ) 7 8 type Vertex struct { 9 X, Y int 10 } 11 12 func (v *Vertex) Print() { 13 fmt.Println("print", v) 14 } 15 16 type PrintInf interface { 17 Print() 18 } 19 20 var uptr *Vertex 21 var uptra *Vertex 22 var strptr *string 23 24 func main() { 25 uptr = new(Vertex) 26 uptra = uptr 27 uptr.X = 1000 28 uptr.Y = 1000 29 uptr = new(Vertex) 30 fmt.Println(uptr, uptra) 31 runtime.GC() 32 runtime.GC() 33 runtime.GC() 34 fmt.Println(uptr.X, uptr.Y, uptra) 35 var str = "I am a string" 36 str = fmt.Sprintf("%s %d", str, uptra.X) 37 strptr = &str 38 fmt.Println(*strptr) 39 runtime.GC() 40 runtime.GC() 41 runtime.GC() 42 fmt.Println(*strptr) 43 }