浏览代码

Fix repeated subscription to dropped scope leak (#3569)

* Fix repeated subscription to dropped scope leak

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
Evan Almloff 5 月之前
父节点
当前提交
e22ea0c2ff
共有 1 个文件被更改,包括 14 次插入0 次删除
  1. 14 0
      packages/core/src/reactive_context.rs

+ 14 - 0
packages/core/src/reactive_context.rs

@@ -311,3 +311,17 @@ struct Inner {
     // The scope that this reactive context is associated with
     scope: Option<ScopeId>,
 }
+
+impl Drop for Inner {
+    fn drop(&mut self) {
+        let Some(self_) = self.self_.take() else {
+            return;
+        };
+
+        for subscriber in std::mem::take(&mut self.subscribers) {
+            if let Ok(mut subscriber) = subscriber.0.lock() {
+                subscriber.remove(&self_);
+            }
+        }
+    }
+}