github.com/giovannyortegon/go@v0.0.0-20220115155912-8890063f5bdd/src/MasterGO/Chap02-GoInternals/sliceGC.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  )
     7  
     8  type data struct {
     9  	i, j int
    10  }
    11  
    12  func main() {
    13  	var N = 40000000
    14  	var structure []data
    15  
    16  	for i:= 0; i < N; i++ {
    17  		value := int(i)
    18  		structure = append(structure,  data{value, value})
    19  	}
    20  
    21  	runtime.GC()
    22  	_ = structure[0]
    23  }