Created
February 21, 2018 06:37
-
-
Save juzipeek/0c743feb2d946fd124e59a0fcd73908c to your computer and use it in GitHub Desktop.
go 主动调用 gc 没有起效果
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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