CurtHagenlocher opened a new pull request, #537: URL: https://github.com/apache/arrow-dotnet/pull/537
### What's changed? Since #534, the buffers of a dictionary hold references to the message body they view. The buffers of a record batch did not: the batch owned its body and disposed it directly. This handles record batches the same way, so a buffer shared from a batch keeps the body it views. That covers `SliceShared`, `ArrayData.Retain`, `Concatenate`, `RunEndEncodedArray.Normalize` and export through the C Data Interface. - The reader wraps a record batch message's body in a `MessageBody`, as it already does for dictionary batches. Each buffer that views the body, including a buffer stored uncompressed in a compressed stream, holds its own reference to it. - The batch holds a reference of its own and releases it when disposed, so the body is released along with the last buffer that refers to it. - A batch read with the default allocator can now be disposed while it is exported. Before, the export pinned the body, and disposing the batch threw `InvalidOperationException`. Readers over a `ReadOnlyMemory<byte>`, and Flight, view memory that the caller or the message owns, so they are unchanged. Each buffer read from a stream now carries a small reference-counting handle. On the reader benchmarks this adds about 4.5 KB of allocation per batch with one column set, with no measurable change in time at the usual batch sizes. With batches of 100 rows, reading from a stream took nearly 50% longer; a follow-up could make this cheaper. ### Testing - New `RecordBatchBodyReferenceTests` cover each way of sharing buffers listed above. They run on a `MemoryStream`, another stream type and the file reader, with uncompressed bodies and compressed bodies that store every buffer uncompressed. They also check that the body is released with the last reference to it, and that readers over memory own nothing. - `CDataInterfacePythonTests.EarlyDisposeOfExportedBatch` now disposes the batch while it is exported and checks that pyarrow still reads the same data. All of `Apache.Arrow.Tests` passes on net472 and net8.0. Co-Authored-By: Claude Opus 5.5 <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_012dFdcrBz22tRjiyNwBd7VB -- 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]
