Skip to content

Instantly share code, notes, and snippets.

@reusee
Created July 27, 2013 14:07
Show Gist options
  • Select an option

  • Save reusee/6094974 to your computer and use it in GitHub Desktop.

Select an option

Save reusee/6094974 to your computer and use it in GitHub Desktop.
makefunc
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