When implementing structures containing multiple HashMap instances, the current separate Collector allocation pattern introduces significant memory overhead.
// Current implementation (high memory cost)
struct Heavy {
state1: HashMap<i32, i32>, // Each has its own Collector
...
state10: HashMap<i32, i32>
}
// Proposed implementation (shared collector)
struct Heavy {
collector: Arc<Collector>, // Shared reference
state1: HashMap<i32, i32>,
...
state10: HashMap<i32, i32>
}
// Reclaim by who owned `Collector`
impl Drop for Heavy {
fn drop(&mut self) {
unsafe { self.collector.reclaim_all() }
}
}