1 | // Reproduces https://github.com/hawkw/sharded-slab/issues/83 |
2 | use memory_stats::memory_stats; |
3 | use sharded_slab::Config; |
4 | use sharded_slab::Slab; |
5 | |
6 | struct CustomConfig; |
7 | impl Config for CustomConfig { |
8 | const RESERVED_BITS: usize = 1; // This is the cause. |
9 | } |
10 | |
11 | #[test] |
12 | fn reserved_bits_doesnt_leak() { |
13 | let slab = Slab::new_with_config::<CustomConfig>(); |
14 | for n in 0..1000 { |
15 | let mem_before = memory_stats().unwrap(); |
16 | let key = slab.insert(0).unwrap(); |
17 | slab.remove(key); |
18 | let usage = memory_stats().unwrap(); |
19 | eprintln!( |
20 | "n: {n:<4} \tkey: {key:#08x} rss: {:>16} vs:{:>16}" , |
21 | usage.physical_mem, usage.virtual_mem |
22 | ); |
23 | |
24 | assert_eq!(mem_before.virtual_mem, usage.virtual_mem); |
25 | } |
26 | } |
27 | |