Compare commits

...

1 Commits

Author SHA1 Message Date
Thorsten Ball
a81574ac8f Debug: add logs for project leaking 2024-10-28 12:19:42 +01:00
2 changed files with 20 additions and 2 deletions

View File

@@ -192,16 +192,23 @@ pub(crate) struct Slot<T>(Model<T>);
pub struct AnyModel { pub struct AnyModel {
pub(crate) entity_id: EntityId, pub(crate) entity_id: EntityId,
pub(crate) entity_type: TypeId, pub(crate) entity_type: TypeId,
entity_name: &'static str,
entity_map: Weak<RwLock<EntityRefCounts>>, entity_map: Weak<RwLock<EntityRefCounts>>,
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
handle_id: HandleId, handle_id: HandleId,
} }
impl AnyModel { impl AnyModel {
fn new(id: EntityId, entity_type: TypeId, entity_map: Weak<RwLock<EntityRefCounts>>) -> Self { fn new(
id: EntityId,
entity_type: TypeId,
entity_name: &'static str,
entity_map: Weak<RwLock<EntityRefCounts>>,
) -> Self {
Self { Self {
entity_id: id, entity_id: id,
entity_type, entity_type,
entity_name,
entity_map: entity_map.clone(), entity_map: entity_map.clone(),
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
handle_id: entity_map handle_id: entity_map
@@ -228,6 +235,7 @@ impl AnyModel {
AnyWeakModel { AnyWeakModel {
entity_id: self.entity_id, entity_id: self.entity_id,
entity_type: self.entity_type, entity_type: self.entity_type,
entity_name: self.entity_name,
entity_ref_counts: self.entity_map.clone(), entity_ref_counts: self.entity_map.clone(),
} }
} }
@@ -261,6 +269,7 @@ impl Clone for AnyModel {
Self { Self {
entity_id: self.entity_id, entity_id: self.entity_id,
entity_type: self.entity_type, entity_type: self.entity_type,
entity_name: self.entity_name,
entity_map: self.entity_map.clone(), entity_map: self.entity_map.clone(),
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
handle_id: self handle_id: self
@@ -285,6 +294,7 @@ impl Drop for AnyModel {
let prev_count = count.fetch_sub(1, SeqCst); let prev_count = count.fetch_sub(1, SeqCst);
assert_ne!(prev_count, 0, "Detected over-release of a model."); assert_ne!(prev_count, 0, "Detected over-release of a model.");
if prev_count == 1 { if prev_count == 1 {
println!("dropping entity: {}", self.entity_name);
// We were the last reference to this entity, so we can remove it. // We were the last reference to this entity, so we can remove it.
let mut entity_map = RwLockUpgradableReadGuard::upgrade(entity_map); let mut entity_map = RwLockUpgradableReadGuard::upgrade(entity_map);
entity_map.dropped_entity_ids.push(self.entity_id); entity_map.dropped_entity_ids.push(self.entity_id);
@@ -374,7 +384,12 @@ impl<T: 'static> Model<T> {
T: 'static, T: 'static,
{ {
Self { Self {
any_model: AnyModel::new(id, TypeId::of::<T>(), entity_map), any_model: AnyModel::new(
id,
TypeId::of::<T>(),
std::any::type_name::<T>(),
entity_map,
),
entity_type: PhantomData, entity_type: PhantomData,
} }
} }
@@ -466,6 +481,7 @@ impl<T> PartialEq<WeakModel<T>> for Model<T> {
pub struct AnyWeakModel { pub struct AnyWeakModel {
pub(crate) entity_id: EntityId, pub(crate) entity_id: EntityId,
entity_type: TypeId, entity_type: TypeId,
entity_name: &'static str,
entity_ref_counts: Weak<RwLock<EntityRefCounts>>, entity_ref_counts: Weak<RwLock<EntityRefCounts>>,
} }
@@ -501,6 +517,7 @@ impl AnyWeakModel {
Some(AnyModel { Some(AnyModel {
entity_id: self.entity_id, entity_id: self.entity_id,
entity_type: self.entity_type, entity_type: self.entity_type,
entity_name: self.entity_name,
entity_map: self.entity_ref_counts.clone(), entity_map: self.entity_ref_counts.clone(),
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
handle_id: self handle_id: self

View File

@@ -1047,6 +1047,7 @@ impl Project {
} }
fn release(&mut self, cx: &mut AppContext) { fn release(&mut self, cx: &mut AppContext) {
println!("-------------------> ssh project. release");
if let Some(client) = self.ssh_client.take() { if let Some(client) = self.ssh_client.take() {
let shutdown = client let shutdown = client
.read(cx) .read(cx)