@@ -41,6 +41,14 @@ pub trait ObjectImpl: ObjectSubclass + ObjectImplExt {
41
41
fn constructed ( & self , obj : & Self :: Type ) {
42
42
self . parent_constructed ( obj) ;
43
43
}
44
+
45
+ /// Disposes of the object.
46
+ ///
47
+ /// When `dispose()` ends, the object should not hold any reference to any other member object.
48
+ /// The object is also expected to be able to answer client method invocations (with possibly an
49
+ /// error code but no memory violation) until it is dropped. `dispose()` can be executed more
50
+ /// than once.
51
+ fn dispose ( & self , _obj : & Self :: Type ) { }
44
52
}
45
53
46
54
unsafe extern "C" fn get_property < T : ObjectImpl > (
@@ -92,6 +100,20 @@ unsafe extern "C" fn constructed<T: ObjectImpl>(obj: *mut gobject_ffi::GObject)
92
100
imp. constructed ( & from_glib_borrow :: < _ , Object > ( obj) . unsafe_cast_ref ( ) ) ;
93
101
}
94
102
103
+ unsafe extern "C" fn dispose < T : ObjectImpl > ( obj : * mut gobject_ffi:: GObject ) {
104
+ let instance = & * ( obj as * mut T :: Instance ) ;
105
+ let imp = instance. get_impl ( ) ;
106
+
107
+ imp. dispose ( & from_glib_borrow :: < _ , Object > ( obj) . unsafe_cast_ref ( ) ) ;
108
+
109
+ // Chain up to the parent's dispose.
110
+ let data = T :: type_data ( ) ;
111
+ let parent_class = data. as_ref ( ) . get_parent_class ( ) as * mut gobject_ffi:: GObjectClass ;
112
+ if let Some ( ref func) = ( * parent_class) . dispose {
113
+ func ( obj) ;
114
+ }
115
+ }
116
+
95
117
/// Definition of a property.
96
118
#[ derive( Clone ) ]
97
119
pub struct Property < ' a > ( pub & ' a str , pub fn ( & str ) -> crate :: ParamSpec ) ;
@@ -273,6 +295,7 @@ unsafe impl<T: ObjectImpl> IsSubclassable<T> for Object {
273
295
klass. set_property = Some ( set_property :: < T > ) ;
274
296
klass. get_property = Some ( get_property :: < T > ) ;
275
297
klass. constructed = Some ( constructed :: < T > ) ;
298
+ klass. dispose = Some ( dispose :: < T > ) ;
276
299
}
277
300
}
278
301
0 commit comments