I believe the pool does not track the objects that it returns from a call 
to `Get()`. I would be surprised if it did track these objects. There is no 
real need for it to track these objects.

The role of a sync pool is to give you an instance of *Object when you need 
it. As an optimisation if it has some pooled instances it will give you 
those instead of creating a new one. Whatever it gives you as a return to 
Get() it doesn't need to keep track of. It can't give that instance to 
anyone else, so it just forgets about it, unless you call Put(), then it 
will track that - so it can give that instance to someone else.

I think now your proposal makes a lot more sense to me. If I understand 
correctly you had understood that the sync.Pool would track all the 
instances of objects it had created, via Get(), and so they wouldn't be 
GCed, This would be (to me) a very surprising implementation of sync.Pool.

On Thursday, 27 September 2018 19:28:07 UTC+2, Peter Mogensen wrote:
>
>
>
> On 09/27/2018 07:19 PM, Francis wrote: 
> > It is true that uintptr is not looked at by the garbage collector. This 
> > will definitely reduce your GC costs. But there is no way (that I know 
> > of) to convert your uintptr back into a *Object that is safe. 
>
> I assume of course that we know that all uintptr in the map is actuall 
> *Object 
>
> > Because uintptr is ignored by the GC it won't keep the memory it points 
> > to alive. So the *Object could, and very likely will, be collected as 
> > garbage. As noted above the sync.Pool is allowed to discard things that 
> > it is pooling. The last time I read the details the strategy was to 
> > clear _everything_ in the pool during a GC run. 
>
> But not objects returned by Get() for which Put() has not yet been 
> called, I assume. ? 
>
> /Peter 
>

-- 
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.

Reply via email to