gsync icon indicating copy to clipboard operation
gsync copied to clipboard

Review use of sync.Pool with slices

Open jannson opened this issue 8 years ago • 2 comments

As I known, the sync.Pool in golang , you must use get/put together. But the code below https://github.com/c4milo/gsync/blob/master/gsync_client.go#L109

you only bufferPool.Put(bfp) when the err is io.EOF, is this ok?

jannson avatar Sep 21 '17 04:09 jannson

I find that buffer from synt.Pool can be gc when the sync.Pool hold the only reference. https://golang.org/src/sync/pool.go line 17

But you should put the buffer to bufferPool event it can be gc outside.

jannson avatar Sep 21 '17 05:09 jannson

@jannson, there is no memory leak as you found out. However, it does put pressure in the GC.

c4milo avatar Sep 21 '17 13:09 c4milo