Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Foundation/NSObject2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public unsafe NSObjectData* Data {
}

public override bool IsInvalid {
get => handle != IntPtr.Zero;
get => handle == IntPtr.Zero;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️

}

protected override bool ReleaseHandle ()
Expand Down Expand Up @@ -147,6 +147,7 @@ unsafe NativeHandle handle {
// having to attach those threads to to the managed runtime.
#nullable enable
NSObjectDataHandle? data_handle;
GCHandle data_handle_gchandle;

internal unsafe NSObjectData* GetData ()
{
Expand All @@ -169,6 +170,7 @@ unsafe NSObjectDataHandle AllocateData ()
if (!Runtime.IsCoreCLR) // This condition (and the assignment to __handle_for_mono if applicable) is trimmed away by the linker.
__data_for_mono = data.Data;

data_handle_gchandle = GCHandle.Alloc (data);
return data;
}

Expand Down Expand Up @@ -452,6 +454,7 @@ void ReleaseManagedRef ()
Runtime.NativeObjectHasDied (handle, this);
}
xamarin_release_managed_ref (handle, user_type.AsByte ());
data_handle_gchandle.Free ();
}

static bool IsProtocol (Type type, IntPtr protocol)
Expand Down