lidavidm commented on code in PR #793:
URL: https://github.com/apache/arrow-go/pull/793#discussion_r3171452125


##########
arrow/cdata/cdata.go:
##########
@@ -940,12 +943,31 @@ type nativeCRecordBatchReader struct {
 
        cur arrow.RecordBatch
        err error
+
+       refCount atomic.Int64
+       cleanUps [2]runtime.Cleanup
+}
+
+func (n *nativeCRecordBatchReader) Retain() {
+       n.refCount.Add(1)
 }
 
-// No need to implement retain and release here as we used 
runtime.SetFinalizer when constructing
-// the reader to free up the ArrowArrayStream memory when the garbage 
collector cleans it up.
-func (n *nativeCRecordBatchReader) Retain()  {}
-func (n *nativeCRecordBatchReader) Release() {}
+func (n *nativeCRecordBatchReader) Release() {
+       debug.Assert(n.refCount.Load() > 0, "too many releases")
+
+       if n.refCount.Add(-1) == 0 {

Review Comment:
   nit, but instead of two atomics you could just do the add, assert that it's 
>= 0, then check for 0



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