@@ -76,9 +76,9 @@ struct NSObjectData {
7676 public NSObject . Flags flags ;
7777 }
7878
79- class NSObjectDataHandle : SafeHandle {
79+ class NSObjectDataHandle : CriticalHandle {
8080 public NSObjectDataHandle ( )
81- : base ( IntPtr . Zero , true )
81+ : base ( IntPtr . Zero )
8282 {
8383 unsafe {
8484 this . handle = ( IntPtr ) NativeMemory . AllocZeroed ( ( nuint ) sizeof ( NSObjectData ) ) ;
@@ -90,7 +90,7 @@ public unsafe NSObjectData* Data {
9090 }
9191
9292 public override bool IsInvalid {
93- get => handle = = IntPtr . Zero ;
93+ get => handle ! = IntPtr . Zero ;
9494 }
9595
9696 protected override bool ReleaseHandle ( )
@@ -452,11 +452,6 @@ void ReleaseManagedRef ()
452452 Runtime . NativeObjectHasDied ( handle , this ) ;
453453 }
454454 xamarin_release_managed_ref ( handle , user_type . AsByte ( ) ) ;
455-
456- unsafe {
457- if ( ! Runtime . IsCoreCLR )
458- __data_for_mono = null ;
459- }
460455 }
461456
462457 static bool IsProtocol ( Type type , IntPtr protocol )
@@ -1005,8 +1000,6 @@ protected virtual void Dispose (bool disposing)
10051000 } else {
10061001 NSObject_Disposer . Add ( this ) ;
10071002 }
1008- // DO NOT dispose data_handle here, we rely on it being disposed by the GC in a later garbage collection
1009- // data_handle.Dispose ();
10101003 }
10111004 }
10121005
@@ -1032,11 +1025,6 @@ private NSObject_Disposer ()
10321025 static internal void Add ( NSObject handle )
10331026 {
10341027 bool call_drain ;
1035-
1036- var success = false ;
1037- handle . data_handle . DangerousAddRef ( ref success ) ;
1038- // 'success' will never be false here, because DangerousAddRef will throw an exception in case of failure.
1039-
10401028 lock ( lock_obj ) {
10411029 handles . Add ( handle ) ;
10421030 call_drain = handles . Count == 1 ;
@@ -1076,10 +1064,8 @@ static void Drain (NSObject ctx)
10761064 handles = drainList1 ;
10771065 }
10781066
1079- foreach ( NSObject x in drainList ) {
1067+ foreach ( NSObject x in drainList )
10801068 x . ReleaseManagedRef ( ) ;
1081- x . data_handle . DangerousRelease ( ) ;
1082- }
10831069 drainList . Clear ( ) ;
10841070
10851071 lock ( lock_obj ) {
0 commit comments