From b3ec800808f5cbe38654525e4199bdb0093e76a6 Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Fri, 23 Aug 2024 17:22:09 +0200 Subject: [PATCH] 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 https://github.com/rerun-io/rerun/issues/7222#issuecomment-2297506490 --- src/array/growable/primitive.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/array/growable/primitive.rs b/src/array/growable/primitive.rs index e443756cb95..89722da8a61 100644 --- a/src/array/growable/primitive.rs +++ b/src/array/growable/primitive.rs @@ -60,7 +60,8 @@ impl<'a, T: NativeType> GrowablePrimitive<'a, T> { #[inline] fn to(&mut self) -> PrimitiveArray { let validity = std::mem::take(&mut self.validity); - let values = std::mem::take(&mut self.values); + let mut values = std::mem::take(&mut self.values); + values.shrink_to_fit(); PrimitiveArray::::new(self.data_type.clone(), values.into(), validity.into()) } @@ -100,7 +101,9 @@ impl<'a, T: NativeType> Growable<'a> for GrowablePrimitive<'a, T> { impl<'a, T: NativeType> From> for PrimitiveArray { #[inline] - fn from(val: GrowablePrimitive<'a, T>) -> Self { - PrimitiveArray::::new(val.data_type, val.values.into(), val.validity.into()) + fn from(mut val: GrowablePrimitive<'a, T>) -> Self { + let mut values = std::mem::take(&mut val.values); + values.shrink_to_fit(); + PrimitiveArray::::new(val.data_type, values.into(), val.validity.into()) } }