Re-iterating and expanding on what was discussed privately:
If you are using a sync.Pool to manage a collection of a single type of object, it should be used *instead* (or at least before) allocating memory yourself. Calling pool.Get() returns you a previously Put() object. If none exists, you either get nil and need to allocate memory yourself, or you get the result of pool.New (if set) which should create a new object.
The difference between using a pool object, and allocating yourself is that since you may have received a previously used object, it won't be zeroed, so if it's important to do so, you must init it yourself.
When you are done with a pool object, you should Put() it back in the pool for future re-use. You technically don't have to, since the GC will collect it when it's considered garbage, but then you've gained nothing from using a sync.Pool. When you call Put() it allows the object to be re-used immediately by someone else (calling Get()), avoiding the needing to create a new object.
The real benefit of a pool is to help create a pattern in the code where values are re-used without needing new allocations; the GC is usually only called when allocations push memory use over a limit, so by avoiding the allocations, you postpone having the GC run. Also, a sync.Pool has some optimizations that improve performance of the pool when used on multi-processor machines as opposed to using a channel, or some other simple scheme.
Using a pool is meant to be an optimization, and is best used when certain conditions apply:
- All objects are the same type and roughly the same size
- Instances of the type are allocated frequently (otherwise why bother?)
- Further allocations are usually not needed (eg: object doesn't contain pointers, slices, maps, or channels which might need more memory)
- Instances have a clear point when they are no longer needed
- When calling Put(x), x is the only reference to the object.
In the common case some/most of these conditions won't apply, and it's probably simpler to just use regular allocation.