This is an automated email from the ASF dual-hosted git repository.

zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-go.git


The following commit(s) were added to refs/heads/main by this push:
     new a7fe8f8b fix(arrow/array): release blocks owned by binary view 
builders (#1673)
a7fe8f8b is described below

commit a7fe8f8ba4b44a3b838fc55384d71aed9d168707
Author: LxxxxxxxL <[email protected]>
AuthorDate: Wed Nov 25 03:27:26 2026 +0800

    fix(arrow/array): release blocks owned by binary view builders (#1673)
    
    ### Rationale for this change
    
    Fixes #1672. Releasing a StringView or BinaryView builder before
    finishing an array leaves out-of-line value buffers allocated. Reserving
    64 bytes and then releasing the builder leaves 32 KiB outstanding with
    the default block size.
    
    ### What changes are included in this PR?
    
    Release the internal block builder when the outer builder's final
    reference is dropped. Finishing an array already transfers its blocks,
    so they continue to live as long as the array needs them.
    
    ### Are these changes tested?
    
    Both regression cases failed with 32768 bytes outstanding on 8f7e2d6.
    They exercise a reservation with no appends and a retained builder
    reused after transferring blocks to an array. The second case reads the
    original array after releasing the builder.
    
    With the change, `go test -race -tags assert,test ./arrow/array` and `go
    test ./...` passed on macOS arm64 with the repository test data
    configured.
    
    ### Are there any user-facing changes?
    
    Builders now free their outstanding block allocations on release. The
    public API is unchanged.
    
    Prepared with OpenAI Codex.
    
    Co-authored-by: powerman2026 <[email protected]>
---
 arrow/array/binary_test.go   | 27 +++++++++++++++++++++++++++
 arrow/array/binarybuilder.go |  1 +
 2 files changed, 28 insertions(+)

diff --git a/arrow/array/binary_test.go b/arrow/array/binary_test.go
index 8e91860d..824c0a49 100644
--- a/arrow/array/binary_test.go
+++ b/arrow/array/binary_test.go
@@ -762,3 +762,30 @@ func TestBinaryViewStringRoundTrip(t *testing.T) {
 
        assert.True(t, Equal(arr, arr1))
 }
+
+func TestViewBuilderReleasesOwnedBlocks(t *testing.T) {
+       t.Run("reserved but unused", func(t *testing.T) {
+               mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
+               b := NewStringViewBuilder(mem)
+               b.ReserveData(64)
+               b.Release()
+               mem.AssertSize(t, 0)
+       })
+
+       t.Run("appended after transferring blocks to an array", func(t 
*testing.T) {
+               mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
+               defer mem.AssertSize(t, 0)
+               b := NewBinaryViewBuilder(mem)
+               value := []byte("a value stored outside the view header")
+               b.Append(value)
+               arr := b.NewBinaryViewArray()
+               defer arr.Release()
+
+               b.Retain()
+               b.Append(value)
+               b.Release()
+               b.Append(value)
+               b.Release()
+               assert.Equal(t, value, arr.Value(0))
+       })
+}
diff --git a/arrow/array/binarybuilder.go b/arrow/array/binarybuilder.go
index 761ab3e2..c5795273 100644
--- a/arrow/array/binarybuilder.go
+++ b/arrow/array/binarybuilder.go
@@ -540,6 +540,7 @@ func (b *BinaryViewBuilder) Release() {
                return
        }
 
+       b.blockBuilder.Release()
        if b.nullBitmap != nil {
                b.nullBitmap.Release()
                b.nullBitmap = nil

Reply via email to