I tried this code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=23d67c52988b3be4eb1ddb6373da124d
fn main() {
let allocator = AllocWrapper(Arc::new(std::alloc::System));
println!("count = {}", Arc::strong_count(&allocator.0));
let mut btree_map: BTreeMap<i32, i32, _> = BTreeMap::new_in(allocator.clone());
println!("count = {}", Arc::strong_count(&allocator.0));
btree_map.insert(1, 1);
println!("count = {}", Arc::strong_count(&allocator.0));
drop(btree_map);
println!("count = {}", Arc::strong_count(&allocator.0)); // expect 1 got 2!
}
I expected to see this happen:
The reference count of the Arc should reduce to 1, so that it can be released correctly.
Instead, this happened:
The reference count of the Arc remains 2, so it will never be released.
Meta
Build using the Nightly version: 1.68.0-nightly
(2022-12-26 88c58e3c2c097ebffac4)
with
#![feature(btreemap_alloc)]
#![feature(allocator_api)]
I tried this code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=23d67c52988b3be4eb1ddb6373da124d
I expected to see this happen:
The reference count of the
Arcshould reduce to 1, so that it can be released correctly.Instead, this happened:
The reference count of the
Arcremains 2, so it will never be released.Meta
with