zed-industries/zed · error

detected over-release of a entity

Error message

detected over-release of a entity

What it means

AnyEntity::clone increments the entity's reference count looked up by entity_id; the expect fires when the count entry is missing, meaning the entity was already fully released and the map slot cleared. Cloning a handle after its count hit zero means a handle outlived entity release — an over-release / use-after-release bug.

Source

Thrown at crates/gpui/src/app/entity_map.rs:318

        if TypeId::of::<T>() == self.entity_type {
            Ok(Entity {
                any_entity: self,
                entity_type: PhantomData,
            })
        } else {
            Err(self)
        }
    }
}

impl Clone for AnyEntity {
    fn clone(&self) -> Self {
        if let Some(entity_map) = self.entity_map.upgrade() {
            let entity_map = entity_map.read();
            let count = entity_map
                .counts
                .get(self.entity_id)
                .expect("detected over-release of a entity");
            let prev_count = count.fetch_add(1, SeqCst);
            assert_ne!(prev_count, 0, "Detected over-release of a entity.");
        }

        Self {
            entity_id: self.entity_id,
            entity_type: self.entity_type,
            entity_map: self.entity_map.clone(),
            #[cfg(any(test, feature = "leak-detection"))]
            handle_id: self
                .entity_map
                .upgrade()
                .unwrap()
                .write()
                .leak_detector
                .handle_created(self.entity_id, None),
        }
    }

View on GitHub (pinned to f4178619ac)

Solutions

  1. Audit code that clones an AnyEntity after the entity has been released
  2. Look for handles stored beyond entity release (e.g. in globals or callbacks firing post-release)
  3. Run with the leak detector enabled to find which handle was dropped twice
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/gpui/src/app/entity_map.rs:318 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/fcc43e3aa10a59ac. Report an issue: GitHub.