Drop check better message

This commit is contained in:
Igor Katson 2024-08-21 16:56:06 +01:00
parent 2ad5fa2f12
commit a5abe97735
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
2 changed files with 18 additions and 6 deletions

View file

@ -149,12 +149,19 @@ impl DropChecks {
name: name.into(),
})
}
}
impl Drop for DropCheck {
fn drop(&mut self) {
if self.obj.upgrade().is_some() {
panic!("memory leak: {}", self.name);
pub fn check(&self) -> anyhow::Result<()> {
let mut still_running = Vec::new();
for dc in self.0.read().iter() {
if dc.obj.upgrade().is_some() {
still_running.push(dc.name.clone())
}
}
if !still_running.is_empty() {
anyhow::bail!(
"still existing objects that were supposed to be dropped: {still_running:#?}"
)
}
Ok(())
}
}