-
-
Save reusee/6094974 to your computer and use it in GitHub Desktop.
makefunc
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 ( | |
| "runtime" | |
| "reflect" | |
| "fmt" | |
| ) | |
| type foo struct {} | |
| func main() { | |
| for i := 0; i < 1024; i++ { | |
| func() { | |
| s := &foo{} | |
| funcType := reflect.TypeOf(func(**foo){}) | |
| // generic code below | |
| funcImpl := func(args []reflect.Value) (rets []reflect.Value) { | |
| fmt.Printf("finalized\n") | |
| return | |
| } | |
| runtime.SetFinalizer(&s, reflect.MakeFunc(funcType, funcImpl).Interface()) | |
| runtime.GC() | |
| }() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment