How reference counting works in Apache Arrow for Go
mainThe library uses reference counting to track memory buffer usage, enabling efficient resource accounting and memory pooling. Objects expose two methods:
Retain(): Increases the reference count by 1.Release(): Decreases the reference count by 1.
When the reference count reaches zero, the associated object is freed. Both methods are safe to call from multiple goroutines.
When to call Retain and Release
| Scenario | Action | Reason |
|---|---|---|
| Taking ownership | Call Retain | If you receive an object and need to access it outside the scope of the current function call. |
| Creating/Receiving | Call Release | You own any object created via New... or Copy... functions, or objects received over a channel. |
| Sending over channels | Call Retain | You must call Retain before sending an object over a channel because the receiver is assumed to take ownership and will eventually call Release. |