fix: leaking stored values (#683)

This commit is contained in:
Greg Johnston 2023-03-14 11:06:36 -04:00 committed by GitHub
parent d6e166f105
commit b988ee85f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

View file

@ -4,7 +4,7 @@ use crate::{
node::NodeId,
runtime::{with_runtime, RuntimeId},
suspense::StreamChunk,
PinnedFuture, ResourceId, SuspenseContext,
PinnedFuture, ResourceId, StoredValueId, SuspenseContext,
};
use futures::stream::FuturesUnordered;
use std::{collections::HashMap, fmt};
@ -255,6 +255,9 @@ impl Scope {
ScopeProperty::Resource(id) => {
runtime.resources.borrow_mut().remove(id);
}
ScopeProperty::StoredValue(id) => {
runtime.stored_values.borrow_mut().remove(id);
}
}
}
}
@ -316,6 +319,7 @@ pub(crate) enum ScopeProperty {
Signal(NodeId),
Effect(NodeId),
Resource(ResourceId),
StoredValue(StoredValueId),
}
/// Creating a [Scope](crate::Scope) gives you a disposer, which can be called

View file

@ -329,7 +329,6 @@ pub fn create_signal<T>(
value: T,
) -> (ReadSignal<T>, WriteSignal<T>) {
let s = cx.runtime.create_signal(value);
//crate::macros::debug_warn!("created signal {:?} at {}", s.0.id, std::panic::Location::caller());
cx.with_scope_property(|prop| prop.push(ScopeProperty::Signal(s.0.id)));
s
}

View file

@ -1,5 +1,5 @@
#![forbid(unsafe_code)]
use crate::{with_runtime, RuntimeId, Scope};
use crate::{with_runtime, RuntimeId, Scope, ScopeProperty};
use std::{cell::RefCell, marker::PhantomData, rc::Rc};
slotmap::new_key_type! {
@ -418,6 +418,7 @@ where
.insert(Rc::new(RefCell::new(value)))
})
.unwrap_or_default();
cx.with_scope_property(|prop| prop.push(ScopeProperty::StoredValue(id)));
StoredValue {
runtime: cx.runtime,
id,