From a81574ac8fc33abb0ca71ebd79f386d7cfbc2d08 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Mon, 28 Oct 2024 12:19:42 +0100 Subject: [PATCH] Debug: add logs for project leaking --- crates/gpui/src/app/entity_map.rs | 21 +++++++++++++++++++-- crates/project/src/project.rs | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/gpui/src/app/entity_map.rs b/crates/gpui/src/app/entity_map.rs index 07aa466295..d4c5edffb9 100644 --- a/crates/gpui/src/app/entity_map.rs +++ b/crates/gpui/src/app/entity_map.rs @@ -192,16 +192,23 @@ pub(crate) struct Slot(Model); pub struct AnyModel { pub(crate) entity_id: EntityId, pub(crate) entity_type: TypeId, + entity_name: &'static str, entity_map: Weak>, #[cfg(any(test, feature = "test-support"))] handle_id: HandleId, } impl AnyModel { - fn new(id: EntityId, entity_type: TypeId, entity_map: Weak>) -> Self { + fn new( + id: EntityId, + entity_type: TypeId, + entity_name: &'static str, + entity_map: Weak>, + ) -> Self { Self { entity_id: id, entity_type, + entity_name, entity_map: entity_map.clone(), #[cfg(any(test, feature = "test-support"))] handle_id: entity_map @@ -228,6 +235,7 @@ impl AnyModel { AnyWeakModel { entity_id: self.entity_id, entity_type: self.entity_type, + entity_name: self.entity_name, entity_ref_counts: self.entity_map.clone(), } } @@ -261,6 +269,7 @@ impl Clone for AnyModel { Self { entity_id: self.entity_id, entity_type: self.entity_type, + entity_name: self.entity_name, entity_map: self.entity_map.clone(), #[cfg(any(test, feature = "test-support"))] handle_id: self @@ -285,6 +294,7 @@ impl Drop for AnyModel { let prev_count = count.fetch_sub(1, SeqCst); assert_ne!(prev_count, 0, "Detected over-release of a model."); if prev_count == 1 { + println!("dropping entity: {}", self.entity_name); // We were the last reference to this entity, so we can remove it. let mut entity_map = RwLockUpgradableReadGuard::upgrade(entity_map); entity_map.dropped_entity_ids.push(self.entity_id); @@ -374,7 +384,12 @@ impl Model { T: 'static, { Self { - any_model: AnyModel::new(id, TypeId::of::(), entity_map), + any_model: AnyModel::new( + id, + TypeId::of::(), + std::any::type_name::(), + entity_map, + ), entity_type: PhantomData, } } @@ -466,6 +481,7 @@ impl PartialEq> for Model { pub struct AnyWeakModel { pub(crate) entity_id: EntityId, entity_type: TypeId, + entity_name: &'static str, entity_ref_counts: Weak>, } @@ -501,6 +517,7 @@ impl AnyWeakModel { Some(AnyModel { entity_id: self.entity_id, entity_type: self.entity_type, + entity_name: self.entity_name, entity_map: self.entity_ref_counts.clone(), #[cfg(any(test, feature = "test-support"))] handle_id: self diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 49f4b7c6f3..6cd249b844 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1047,6 +1047,7 @@ impl Project { } fn release(&mut self, cx: &mut AppContext) { + println!("-------------------> ssh project. release"); if let Some(client) = self.ssh_client.take() { let shutdown = client .read(cx)