Skip to content

Commit

Permalink
cleanup memory accounting
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Jul 4, 2023
1 parent 51b0243 commit 68f62d1
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ impl GroupsAccumulatorAdapter {
where
F: Fn() -> Result<Box<dyn Accumulator>> + Send + 'static,
{
Self {
let mut new_self = Self {
factory: Box::new(factory),
states: vec![],
allocation_bytes: std::mem::size_of::<GroupsAccumulatorAdapter>(),
}
allocation_bytes: 0,
};
new_self.reset_allocation();
new_self
}

// Reset the allocation bytes to empty state
fn reset_allocation(&mut self) {
assert!(self.states.is_empty());
self.allocation_bytes = std::mem::size_of::<GroupsAccumulatorAdapter>();
}

/// Ensure that self.accumulators has total_num_groups
Expand Down Expand Up @@ -243,7 +251,9 @@ impl GroupsAccumulator for GroupsAccumulatorAdapter {
.map(|state| state.accumulator.evaluate())
.collect::<Result<_>>()?;

ScalarValue::iter_to_array(results)
let result = ScalarValue::iter_to_array(results);
self.reset_allocation();
result
}

fn state(&mut self) -> Result<Vec<ArrayRef>> {
Expand Down Expand Up @@ -277,6 +287,7 @@ impl GroupsAccumulator for GroupsAccumulatorAdapter {
}
}

self.reset_allocation();
Ok(arrays)
}

Expand Down

0 comments on commit 68f62d1

Please sign in to comment.