package pool_test import ( "fmt" "runtime" "sync" "testing" "time" ) func TestPool1(t *testing.T) { p := &sync.Pool{ New: func() any { return make([]map[string]any, 0, 100) }, } ms := p.Get().([]map[string]any) for i := 1; i < 100; i++ { m := map[string]any{"": i} runtime.SetFinalizer(&m, func(o *map[string]any) { fmt.Println("Object ", (*o)[""], " has been garbage collected") }) ms = append(ms, m) } p.Put(ms[:0]) runtime.GC() time.Sleep(1 * time.Minute) }