Skip to content

arrow: Fix memory leak in ColumnVector by caching decoded vector - #17738

Open
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/iceberg-17722-arrow-vector-leak
Open

arrow: Fix memory leak in ColumnVector by caching decoded vector#17738
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/iceberg-17722-arrow-vector-leak

Conversation

@waterWang

Copy link
Copy Markdown

Every call to ColumnVector.getArrowVector() on a dictionary-encoded column allocates a new decoded FieldVector that is never released. Since ColumnarBatch.createVectorSchemaRootFromVectors() calls it for every column of every batch, a scan over dict-encoded data leaks one vector per batch per dict-encoded column, and the memory survives a fully drained and fully closed scan.

Root cause

ColumnVector.getArrowVector() routes dict-encoded columns through DictEncodedArrowConverter.toArrowVector() which allocates and populates a new vector from the reader's allocator on each call. ColumnVector.close() only closes the accessor, never the decoded vector.

Fix

Cache the decoded vector in a private field, materializing it once per batch instead of on every getArrowVector() call, and release it in close(). Repeated calls within the same batch return the same cached vector. This matches the documented contract ("the arrow vectors are owned by the reader").

Closes #17722

Every call to getArrowVector() on a dictionary-encoded column allocated
a new decoded FieldVector that was never released. Since
ColumnarBatch.createVectorSchemaRootFromVectors() calls it for every
column of every batch, a scan over dict-encoded data leaked one vector
per batch per dict-encoded column.

Fix: cache the decoded vector in a private field (lazy init), and
release it in close(). Repeated calls to getArrowVector() within the
same batch return the same cached vector.

Closes apache#17722
@waterWang waterWang changed the title arrow: Fix memory leak in ColumnVector by caching decoded vector [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] arrow: Fix memory leak in ColumnVector by caching decoded vector Aug 20, 2026
@github-actions github-actions Bot added the arrow label Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arrow: ColumnVector.getArrowVector() leaks direct memory for dictionary encoded columns

1 participant