Skip to content

Commit

Permalink
Avoid memory leaking
Browse files Browse the repository at this point in the history
  • Loading branch information
Shute052 committed Feb 4, 2024
1 parent d7b1a3d commit 6cea797
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/input_streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ pub(crate) fn read_logical_key_changes<'a>(
caches.insert(logical_key.clone());
} else {
caches.remove(logical_key);

// TODO: These magic numbers are just intuitive guesses, not tested or validated.
// Avoid memory leaking
let len = caches.len();
let capacity = caches.capacity();
if capacity > 8 * len {
caches.shrink_to(2 * len);
}
}
}
}
Expand Down

0 comments on commit 6cea797

Please sign in to comment.