zeroshade commented on issue #43791:
URL: https://github.com/apache/arrow/issues/43791#issuecomment-2305232286

   > 1. It was stated in the above issue that when using the default Go 
allocator, we "don't actually have to call `Retain`/`Release`", but
   >    * Would calling `Retain`/`Release` properly help Go GC do its job more 
timely/accurately?
   >    * Would calling `Retain`/`Release` wrongly make Go GC perform worse 
(i.e. memory leaks) or even lead to bugs?
   
   Calling it properly could potentially help the GC because it will mark 
slices and buffers as nil earlier on allowing the GC to clean it up sooner. 
Calling it incorrectly would, at best, have no real effect when using the 
default Go allocator, and at worst it will nil out the values too soon and 
cause a panic the next time you try to access it.
   
   > 2. If I want to call Retain/Release properly, how should I do it? How can 
I know if an Arrow Record returned by an Arrow library function (or any 
third-party library function) is already Retained or not?
   
   For the Arrow library functions, they should all be properly documented as 
far as if they call `Retain` internally or require the result to separately 
have `Release` called on it. In general, anything that creates a new record 
will need to have Release called on it. The other general pattern is that 
Record readers will call release on the current record each time 
`reader.Next()` is called, requiring you to call `Retain` if you need a record 
to exist outside of the read loop. For example:
   
   ```go
   recordlist := make([]arrow.Record, 0)
   for reader.Next() {
         rec := reader.Record()
         // each call to reader.Next() will release the current rec
         // so you need to call rec.Retain() if you add it to a slice
         // and want it to last past this loop.
         recordlist = append(recordlist, rec)
         // this does mean you'll need to eventually release all 
         // these records. 
   }
   
   defer func() {
       for _, r := range recordlist {
            r.Release()
       }
   }()
   ```
   
   Does this help out at all?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to