Hello, So I'm starting to play with sync pool on a program that needs to allocate a ton of short lived objects per server request. Performance seems to be better when using sync pool however I've noticed that upon releasing the object and then retrieving it again, will produce a "new object" with "old request data". The solution for this would be to reset the object values/structs to 0, however I feel this will kinda defeat the purpose of using sync pool. After all, we will always be creating new objects.
Given that sync pool is used to avoid overhead when creating a lot of elements, i would assume that I'm missing something here. Could anyone please shred some light on this? package main import( "sync" "fmt" ) type struct1 struct{ obj1 struct2 obj2 struct3 } type struct2 struct{ a string } type struct3 struct{ a string } func AcquireStruct1() *struct1 { return struct1pool.Get().(*struct1) } func ReleaseStruct1(u *struct1 ) { //u.Reset() struct1pool.Put(u) } var struct1pool= &sync.Pool{ New: func() interface{} { a:=&struct1{} return a }, } func main(){ a:=AcquireStruct1() a.obj1.a="a" a.obj2.a="a" ReleaseStruct1(a) a=AcquireStruct1() fmt.Printf("%+v", a) // this outputs the data assigned to the first object } } https://play.golang.org/p/JHHdwG1aqc Thanks in advance. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.