Whoops, forgot to not leak all the RAMs

This commit is contained in:
Dustin Carlino 2021-11-11 14:10:42 -08:00
parent 006839aec2
commit 08223efed5
4 changed files with 20 additions and 0 deletions

View File

@ -230,6 +230,10 @@ impl<K: Clone + PartialEq, V> VecMap<K, V> {
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
pub fn clear(&mut self) {
self.inner.clear();
}
}
impl<K: Clone + PartialEq, V> Default for VecMap<K, V> {

View File

@ -115,6 +115,10 @@ impl State<App> for RoutePlanner {
let panel_outcome = self.panel.event(ctx);
if let Outcome::Clicked(ref x) = panel_outcome {
if x == "Back to editing modal filters" {
// We'll cache a custom pathfinder per set of avoided roads. Avoid leaking memory
// by clearing this out
app.primary.map.clear_custom_pathfinder_cache();
return Transition::ConsumeState(Box::new(|state, ctx, app| {
let state = state.downcast::<RoutePlanner>().ok().unwrap();
vec![super::viewer::Viewer::new_state(

View File

@ -605,6 +605,11 @@ impl Map {
self.pathfinder.should_use_transit(self, start, end)
}
/// Clear any pathfinders with custom RoutingParams, created previously with `cache_custom`
pub fn clear_custom_pathfinder_cache(&self) {
self.pathfinder.clear_custom_pathfinder_cache();
}
/// Return the cost of a single path, and also a mapping from every directed road to the cost
/// of getting there from the same start. This can be used to understand why an alternative
/// route wasn't chosen.

View File

@ -213,6 +213,13 @@ impl Pathfinder {
result
}
pub fn clear_custom_pathfinder_cache(&self) {
self.cached_alternatives
.get_or(|| RefCell::new(VecMap::new()))
.borrow_mut()
.clear();
}
pub fn all_costs_from(
&self,
req: PathRequest,