This sounds much like the trickery people have used both successfully but also disastrously using weak references in Java. Is that where you got the idea from?
fre 28 sep. 2018 kl 08:36 skrev Keith Randall <keith.rand...@gmail.com>: > On Thu, Sep 27, 2018 at 11:26 PM Peter Mogensen <a...@one.com> wrote: > >> >> >> On 09/28/2018 08:17 AM, Peter Mogensen wrote: >> > >> > >> > On 09/28/2018 03:04 AM, keith.rand...@gmail.com wrote: >> >> Objects returned by Get() are not special in any way. They will be GCd >> >> just like an object returned by new(). In fact, they will often be just >> >> a new()'d object. >> >> There is no association of such an object with the pool. A pool is >> just >> >> a fancy free list. Get might return a previously Put'd object instead >> of >> >> a new() one. >> >> >> >> Your scheme is unsafe. Storing a *Object as a uintptr means the >> >> underlying Object will be collected out from under your map. >> > >> > Ok... thanks... I guess I might have made the wrong assumption about >> > when objects returned from pool.Get() are subject to garbage collection. >> > >> >> >> However... (it's early here, so I forgot). >> >> Of course the uintptr entries in the map is not the only reference to >> the objects. In order to properly clean up there will be another >> datastructure holding (say) a linked list of the objects. >> >> For instance... if the map is only used as index to a huge database, >> where the objects are actually stored in a priority queue to, say, >> implement TTL or LRU. >> >> So, there would always be another reference to the objects preventing >> them for being garbage collected. >> >> > It's not guaranteed to work according to the spec. The thing that will > break your code is moving objects. > The GC currently doesn't move objects in the heap. > We do copy stacks, but the current escape analysis never puts objects > pointed to by a map entry on the stack. > So for now, you're ok. If we ever implement a moving garbage collector or > improve escape analysis, you're out of luck. > > >> /Peter > > >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "golang-nuts" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/golang-nuts/NPdHLvOoCp8/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> golang-nuts+unsubscr...@googlegroups.com. > > >> For more options, visit https://groups.google.com/d/optout. >> > -- > 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. > -- 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.