Skip to content

Instantly share code, notes, and snippets.

@juzipeek
Created February 21, 2018 06:37
Show Gist options
  • Save juzipeek/0c743feb2d946fd124e59a0fcd73908c to your computer and use it in GitHub Desktop.
Save juzipeek/0c743feb2d946fd124e59a0fcd73908c to your computer and use it in GitHub Desktop.
go 主动调用 gc 没有起效果
package main
import "fmt"
import "time"
import "runtime"
type User struct {
name string
age int
des [10240]byte
}
func alloc(){
all :=make([]*User, 100)
for i:=0;i<1000000;i++{
u := new(User)
u.age = i
all = append(all, u)
}
}
func main() {
alloc()
var input int
fmt.Scan(&input)
fmt.Println(input)
runtime.GC()
fmt.Println("gc complete")
for i:=0; i < 1000; i++ {
u := User{}
u.name = "alloc"
time.Sleep(10*time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment