@@ -21,7 +21,6 @@ pub struct InstanceStorage<T: GodotClass> {
2121
2222 // Declared after `user_instance`, is dropped last.
2323 pub ( super ) lifecycle : cell:: Cell < Lifecycle > ,
24- has_surplus_ref : cell:: Cell < bool > ,
2524
2625 // No-op in Release mode.
2726 borrow_tracker : DebugBorrowTracker ,
@@ -48,7 +47,6 @@ unsafe impl<T: GodotClass> Storage for InstanceStorage<T> {
4847 user_instance : GdCell :: new ( user_instance) ,
4948 base,
5049 lifecycle : cell:: Cell :: new ( Lifecycle :: Alive ) ,
51- has_surplus_ref : cell:: Cell :: new ( false ) ,
5250 borrow_tracker : DebugBorrowTracker :: new ( ) ,
5351 }
5452 }
@@ -57,10 +55,6 @@ unsafe impl<T: GodotClass> Storage for InstanceStorage<T> {
5755 self . user_instance . is_currently_bound ( )
5856 }
5957
60- fn mark_surplus_ref ( & self ) {
61- self . has_surplus_ref . set ( true ) ;
62- }
63-
6458 fn base ( & self ) -> & Base < <Self :: Instance as GodotClass >:: Base > {
6559 & self . base
6660 }
@@ -105,25 +99,18 @@ unsafe impl<T: GodotClass> Storage for InstanceStorage<T> {
10599
106100impl < T : GodotClass > StorageRefCounted for InstanceStorage < T > {
107101 fn on_inc_ref ( & self ) {
108- if self . has_surplus_ref . get ( ) {
109- self . has_surplus_ref . set ( false ) ;
110-
111- return ; // If we have surplus references, we don't increment the ref count.
112- }
102+ // Note: on_inc_ref() and on_dec_ref() do not track extra strong references from Base::to_init_gd().
103+ // See https://github.com/godot-rust/gdext/pull/1273 for code that had it.
113104
114105 super :: log_inc_ref ( self ) ;
115106 }
116107
117108 fn on_dec_ref ( & self ) {
118- // IMPORTANT: it is too late here to perform dec-ref operations on the Base (for "surplus" references).
109+ // IMPORTANT: it is too late here to perform dec-ref operations on the Base (for "surplus" strong references).
119110 // This callback is only invoked in the C++ condition `if (rc_val <= 1 /* higher is not relevant */)` -- see Godot ref_counted.cpp.
120111 // The T <-> RefCounted hierarchical relation is usually already broken up at this point, and further dec-ref may bring the count
121112 // down to 0.
122113
123- if self . has_surplus_ref . get ( ) {
124- self . has_surplus_ref . set ( false ) ;
125- }
126-
127114 super :: log_dec_ref ( self ) ;
128115 }
129116}
0 commit comments