-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak? Inserted value will never be dropped? #23
Comments
Maybe I am using crossbeam-epoch 0.8.2.
|
I read the document about
To confirm, I will need to store more data so that crossbeam-epoch's cache will be filled up and drop some values. |
I wrote another code and verified that majority of the replaced values were dropped. I believe crossbeam-epoch and cht are working as expected. use cht::HashMap;
use std::sync::Arc;
fn main() {
const CAP: usize = 10;
const N_INSERTS: usize = CAP * 1_000;
let cht = HashMap::with_capacity(CAP);
let mut handles = Vec::with_capacity(N_INSERTS);
for _ in 0..N_INSERTS {
let v = Arc::new("*".to_string());
cht.insert(0, Arc::clone(&v));
handles.push(Arc::downgrade(&v));
}
let dropped = handles
.into_iter()
.filter(|v| v.strong_count() == 0)
.count();
println!("inserted: {}, dropped: {}", N_INSERTS, dropped);
} $ cargo run --release --bin main2
...
inserted: 10000, dropped: 9832 |
It seems
cht::HashMap
will never drop inserted values when they are removed from the map or replaced by new values. Instead, a clone of a value will be created and the clone will be dropped. The following code will illustrate the problem.The text was updated successfully, but these errors were encountered: