CurtHagenlocher commented on code in PR #543:
URL: https://github.com/apache/arrow-dotnet/pull/543#discussion_r4807087637


##########
src/Apache.Arrow/Ipc/ArrowReaderImplementation.cs:
##########
@@ -168,6 +167,35 @@ internal static ByteBuffer 
CreateByteBuffer(ReadOnlyMemory<byte> buffer)
             return new ByteBuffer(new ReadOnlyMemoryBufferAllocator(buffer), 
0);
         }
 
+        /// <summary>
+        /// Builds a record batch whose buffers hold references to the message 
body, so that anything
+        /// that shares them, such as a slice, a retained array or an exported 
array, keeps the body
+        /// alive after the batch is disposed. The batch holds no reference of 
its own: the body is
+        /// released along with the last buffer that refers to it.
+        /// </summary>
+        /// <param name="memoryOwner">
+        /// The message body, of which this takes ownership, including on 
failure.
+        /// </param>
+        private RecordBatch ReadRecordBatch(
+            MetadataVersion version,
+            Flatbuf.RecordBatch recordBatch,
+            ByteBuffer bodyByteBuffer,
+            IMemoryOwner<byte> memoryOwner)
+        {
+            MessageBody body = memoryOwner == null ? null : new 
MessageBody(memoryOwner);
+            try
+            {
+                List<IArrowArray> arrays = BuildArrays(version, Schema, 
bodyByteBuffer, recordBatch, body);
+                return new RecordBatch(Schema, memoryOwner: null, arrays, 
(int)recordBatch.Length);
+            }
+            finally
+            {
+                // Each buffer that views the body holds its own reference to 
it. A compressed body
+                // is viewed only by buffers stored uncompressed, so it is 
often released here.
+                body?.Release();

Review Comment:
   This was already the case on this branch before this change: when 
`BuildArrays` failed, the body was dropped without being disposed, and so were 
any buffers already decompressed. On main, releasing partially built arrays on 
failure was added separately in #526, which isn't on `maint-23.x`. This PR 
keeps the scope to buffers holding their body, so I've clarified the doc for 
the failure case rather than adding the cleanup here.



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