apache / apache/arrow-java

[Java] DictionaryProvider leaks memory while adding dictionaries with duplicate encoding

Open
#313 7 comments 0 reactions 0 assignees View on GitHub
Type: bug
Dominant language
Java
Stars
94
Forks
152
Avg merge
3d 16h
Merged PRs (30d)
11

Description

DictionaryProvider leaks memory while adding dictionaries with duplicate encoding. Is this expected? Should the provider release the memory of the existing dictionary vector if it accepts another one with same encoding id ?

Sample code:
```java

"dictionaryProvider" should " not leak memory while adding dictionaries with duplicate encoding" in {

val allocator: RootAllocator = new RootAllocator()

val vector: ListVector = ListVector.empty("vector", allocator)
val dictionaryVector1: ListVector = ListVector.empty("dict1", allocator)
val dictionaryVector2: ListVector = ListVector.empty("dict2", allocator)

val writer1: UnionListWriter = vector.getWriter
writer1.allocate
writer1.setValueCount(1)

val dictWriter1: UnionListWriter = dictionaryVector1.getWriter
dictWriter1.allocate
dictWriter1.setValueCount(1)

val dictWriter2: UnionListWriter = dictionaryVector2.getWriter
dictWriter2.allocate
dictWriter2.setValueCount(1)

val dictionary1: Dictionary = new Dictionary(dictionaryVector1, new DictionaryEncoding(1L, false, None.orNull))
val dictionary2: Dictionary = new Dictionary(dictionaryVector2, new DictionaryEncoding(1L, false, None.orNull))

val provider = new DictionaryProvider.MapDictionaryProvider
provider.put(dictionary1)
provider.put(dictionary2)

vector.clear()
provider.getDictionaryIds.asScala.map(id => provider.lookup(id).getVector.clear())

allocator.getAllocatedMemory shouldBe 0
}
```

**Reporter**: [Vimal Varghese](https://issues.apache.org/jira/browse/ARROW-16920)

**Note**: *This issue was originally created as [ARROW-16920](https://issues.apache.org/jira/browse/ARROW-16920). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*

Contributor guide

Open the contributing guide

Research direction

Start at DictionaryProvider.MapDictionaryProvider and run the supplied reproduction that adds two dictionaries with encoding ID 1, clears the vector, and checks allocator memory. Trace what happens to the first dictionary when the second is inserted; done means the duplicate-encoding case releases all allocated memory and the final allocation check reaches zero.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.