-
-
Notifications
You must be signed in to change notification settings - Fork 76
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 after moka::sync::Cache
is dropped
#176
Comments
Thank you so much for reporting the issue. I verified the memory leak at No memory lost// [dependencies]
// moka = "=0.9.3"
// crossbeam-epoch = "=0.9.10"
fn main() {
let cache = moka::sync::Cache::builder()
.max_capacity(1000)
.thread_pool_enabled(false) // This is important.
.build();
for i in 0..1000u32 {
cache.insert(i, i);
}
// This is also important.
for i in 0..1000u32 {
cache.invalidate(&i);
}
drop(cache);
// std::thread::sleep(std::time::Duration::from_secs(1));
// crossbeam_epoch::pin().flush();
} ==16840== LEAK SUMMARY:
==16840== definitely lost: 0 bytes in 0 blocks
==16840== indirectly lost: 0 bytes in 0 blocks
==16840== possibly lost: 0 bytes in 0 blocks
==16840== still reachable: 13,104 bytes in 7 blocks
==16840== suppressed: 0 bytes in 0 blocks 76 bytes lostThis is expected. fn main() {
let cache = moka::sync::Cache::builder()
.max_capacity(1000)
// .thread_pool_enabled(false)
.build();
for i in 0..1000u32 {
cache.insert(i, i);
}
for i in 0..1000u32 {
cache.invalidate(&i);
}
drop(cache);
std::thread::sleep(std::time::Duration::from_secs(1));
crossbeam_epoch::pin().flush();
} ==17334== LEAK SUMMARY:
==17334== definitely lost: 0 bytes in 0 blocks
==17334== indirectly lost: 0 bytes in 0 blocks
==17334== possibly lost: 76 bytes in 1 blocks
==17334== still reachable: 20,408 bytes in 12 blocks
==17334== suppressed: 0 bytes in 0 blocks 1,228 bytes lostfn main() {
let cache = moka::sync::Cache::builder()
.max_capacity(1000)
// .thread_pool_enabled(false)
.build();
for i in 0..1000u32 {
cache.insert(i, i);
}
for i in 0..1000u32 {
cache.invalidate(&i);
}
drop(cache);
// std::thread::sleep(std::time::Duration::from_secs(1));
// crossbeam_epoch::pin().flush();
} ==18144== definitely lost: 0 bytes in 0 blocks
==18144== indirectly lost: 0 bytes in 0 blocks
==18144== possibly lost: 1,228 bytes in 5 blocks
==18144== still reachable: 17,524 bytes in 41 blocks
==18144== suppressed: 0 bytes in 0 blocks 80,000 bytes lostThis is unexpected (bug). fn main() {
let cache = moka::sync::Cache::builder()
.max_capacity(1000)
.thread_pool_enabled(false)
.build();
for i in 0..1000u32 {
cache.insert(i, i);
}
// for i in 0..1000u32 {
// cache.invalidate(&i);
// }
drop(cache);
// std::thread::sleep(std::time::Duration::from_secs(1));
// crossbeam_epoch::pin().flush();
} ==17642== LEAK SUMMARY:
==17642== definitely lost: 48,000 bytes in 1,000 blocks
==17642== indirectly lost: 32,000 bytes in 1,000 blocks
==17642== possibly lost: 0 bytes in 0 blocks
==17642== still reachable: 6,888 bytes in 4 blocks
==17642== suppressed: 0 bytes in 0 blocks |
Hi @losfair, Sorry for the bug. I have fixed the last one with "80,000 bytes lost" via #177. Now running your reproducing code with =23552== LEAK SUMMARY:
==23552== definitely lost: 0 bytes in 0 blocks
==23552== indirectly lost: 0 bytes in 0 blocks
==23552== possibly lost: 1,228 bytes in 5 blocks
==23552== still reachable: 11,252 bytes in 37 blocks
==23552== suppressed: 0 bytes in 0 blocks For the "possibly lost" stuff, you could mitigate it by calling let cache = moka::sync::Cache::builder()
.max_capacity(1000)
.thread_pool_enabled(false)
.build(); This method was added to Moka v0.9.3, and I am going to run pre-release tests, and if they go well, I will publish Moka v0.9.4 (with the fix) to crates.io. |
Thank you so much for the quick fix! |
I have published Moka v0.9.4 to crates.io. |
After a
sync::Cache
is dropped, it seems like some memory is not freed.Reproduce:
and run it with Valgrind:
The text was updated successfully, but these errors were encountered: