diff --git a/expire_set/src/lib.rs b/expire_set/src/lib.rs
index 21d9981..9522f90 100644
@@ -51,8 +51,13 @@ impl<K: std::hash::Hash + Eq + Clone + Send + Sync + 'static> ExpireSet<K> {
tokio::time::sleep(Duration::from_secs(expire)).await;
unsafe {
let n = n_ptr.get();
- let cache = cache_ptr.get();
let current = (*n).load(Ordering::Relaxed);
+ if current > 1 {
+ // 手动回收之前泄露的内存
+ let _ = Box::from_raw(n as *mut AtomicUsize);
+ return;
+ }
+ let cache = cache_ptr.get();
let next = (current + 1) % 2;
(*cache)[next].clear();
(*n).store(next, Ordering::Relaxed);
@@ -83,10 +88,8 @@ impl<K: std::hash::Hash + Eq + Clone + Send + Sync + 'static> ExpireSet<K> {
impl<K> Drop for ExpireSet<K> {
fn drop(&mut self) {
- self.timer.abort();
- // 手动回收之前泄露的内存
+ (*self.n).store(usize::MAX, Ordering::Relaxed);
unsafe {
- let _ = Box::from_raw(self.n as *mut AtomicUsize);
let _ = Box::from_raw(self.cache as *mut [DashSet<K>; 2]);
}
}