Skip to content

Commit b3ec800

Browse files
authored
fix primitive capacity leak (#9)
This fixes the extra capacity from the temporary growable vector leaking into the final buffer and therefore hanging around indefinitely. See rerun-io/rerun#7222 (comment)
1 parent 65da4f3 commit b3ec800

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/array/growable/primitive.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ impl<'a, T: NativeType> GrowablePrimitive<'a, T> {
6060
#[inline]
6161
fn to(&mut self) -> PrimitiveArray<T> {
6262
let validity = std::mem::take(&mut self.validity);
63-
let values = std::mem::take(&mut self.values);
63+
let mut values = std::mem::take(&mut self.values);
64+
values.shrink_to_fit();
6465

6566
PrimitiveArray::<T>::new(self.data_type.clone(), values.into(), validity.into())
6667
}
@@ -100,7 +101,9 @@ impl<'a, T: NativeType> Growable<'a> for GrowablePrimitive<'a, T> {
100101

101102
impl<'a, T: NativeType> From<GrowablePrimitive<'a, T>> for PrimitiveArray<T> {
102103
#[inline]
103-
fn from(val: GrowablePrimitive<'a, T>) -> Self {
104-
PrimitiveArray::<T>::new(val.data_type, val.values.into(), val.validity.into())
104+
fn from(mut val: GrowablePrimitive<'a, T>) -> Self {
105+
let mut values = std::mem::take(&mut val.values);
106+
values.shrink_to_fit();
107+
PrimitiveArray::<T>::new(val.data_type, values.into(), val.validity.into())
105108
}
106109
}

0 commit comments

Comments
 (0)