ShivamSharma43 opened a new pull request, #1697:
URL: https://github.com/apache/arrow-go/pull/1697

   ### Rationale for this change
   
   `compute.Unique` leaks memory for binary, string, large binary/string, fixed 
size binary, decimal128/256 and `month_day_nano_interval` inputs. With a 
checked allocator passed through `compute.WithAllocator`:
   
   ```
   LEAK of 64 bytes FROM
   LEAK of 128 bytes FROM
   ...
   ```
   
   These types are hashed with a `hashing.BinaryMemoTable`, and its builder 
allocates from the context allocator. `dictionaryEncodeFinalize` releases that 
table through `releaseHashMemo`, but `uniqueFinalize` never does, so each 
`unique` call leaves the memo table's buffers allocated. With the Go allocator 
the GC eventually frees them. With an allocator that needs an explicit free, 
such as the mallocator, they leak.
   
   The existing unique tests didn't catch this because they call 
`compute.UniqueArray(context.TODO(), ...)`, so the memo table used the default 
allocator, not the checked one.
   
   ### What changes are included in this PR?
   
   `uniqueFinalize` now defers `releaseHashMemo(impl)`, the same way 
`dictionaryEncodeFinalize` does. `GetDictionary` copies the values out of the 
memo table into new buffers, so releasing the table after that is safe. 
`regularHashState.Reset` already makes a new table if the old one was released.
   
   ### Are these changes tested?
   
   Yes. `TestUniqueReleasesBinaryMemoTable` runs `unique` on array and chunked 
input for each affected type with a checked allocator in the context, and 
checks that the results are right and nothing is left allocated. Without the 
fix every subtest reports leaks.
   
   On Windows amd64 with Go 1.26.11, `go test -tags assert,test 
./arrow/compute/...` and `go test -short -tags assert,test,noasm 
./arrow/compute/...` pass, and `go vet` is clean for the changed packages.
   
   ### Are there any user-facing changes?
   
   No API changes. `unique` no longer leaks memory for these types.
   
   This PR was prepared with AI assistance (Claude Code).
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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