瀏覽代碼

fix: Properly drop UseFuture's values to avoid leaking memory

Marc Espín 2 年之前
父節點
當前提交
1546fce485
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      packages/hooks/src/usefuture.rs

+ 8 - 0
packages/hooks/src/usefuture.rs

@@ -89,6 +89,14 @@ pub struct UseFuture<T> {
     values: Rc<RefCell<Vec<*mut T>>>,
 }
 
+impl<T> Drop for UseFuture<T> {
+    fn drop(&mut self) {
+        for value in self.values.take().into_iter() {
+            drop(unsafe { Box::from_raw(value) })
+        }
+    }
+}
+
 pub enum UseFutureState<'a, T> {
     Pending,
     Complete(&'a T),