diff --git a/glib/src/object.rs b/glib/src/object.rs index 4e1f5bf7c227..98edbc34e5bb 100644 --- a/glib/src/object.rs +++ b/glib/src/object.rs @@ -2228,6 +2228,20 @@ pub trait ObjectExt: ObjectType { // rustdoc-stripper-ignore-next /// Returns the strong reference count of this object. fn ref_count(&self) -> u32; + + // rustdoc-stripper-ignore-next + /// Runs the dispose mechanism of the object. + /// + /// This will dispose of any references the object has to other objects, and among other things + /// will disconnect all signal handlers. + /// + /// # Safety + /// + /// Theoretically this is safe to run and afterwards the object is simply in a non-functional + /// state, however many object implementations in C end up with memory safety issues if the + /// object is used after disposal. + #[doc(alias = "g_object_run_dispose")] + unsafe fn run_dispose(&self); } impl ObjectExt for T { @@ -3125,6 +3139,10 @@ impl ObjectExt for T { unsafe { ffi::g_atomic_int_get(&(*ptr).ref_count as *const u32 as *const i32) as u32 } } + + unsafe fn run_dispose(&self) { + gobject_ffi::g_object_run_dispose(self.as_ptr() as *mut _); + } } // Helper struct to avoid creating an extra ref on objects inside closure watches. This is safe