internal override void StopInThread() { PublishNotificationIterator.Dispose(); PublishNotificationIterator = null; TerminateNotificationIterator.Dispose(); TerminateNotificationIterator = null; Interop.NativeMethods.CFRunLoopRemoveSource(CFRunLoop.Current, NotificationPort.RunLoopSource, (NSString)CFRunLoop.ModeDefault); NotificationPort.Dispose(); NotificationPort = null; Interop.NativeMethods.CFRunLoopRemoveSource(CFRunLoop.Current, IOConnectionPort.NotificationPort.RunLoopSource, (NSString)CFRunLoop.ModeCommon); IOConnectionPort.Dispose(); IOConnectionPort = null; }
/// <inheritdoc/> protected override void Dispose(bool disposing) { if (!Disposed) { DebugOutput("**** IOConnect.Dispose(bool) for " + GetType() + " marking disposed, RetainCount: " + RetainCount); Disposed = true; // The order of disposal here is based on the example at: // https://developer.apple.com/library/content/qa/qa1340/_index.html // Alternative ordering has not been tested. // Also, this code assumes that the NotificationPort has been removed from any run loops. // First, de-register the notifier. if (Notifier != null) { Notifier.Dispose(); } Notifier = null; // Now, close this IO connection. var handle = Handle; if (handle != System.IntPtr.Zero) { IOService.Close(this); ClearHandle(); } // Finally, destroy the notification port itself. if (NotificationPort != null) { NotificationPort.Dispose(); } NotificationPort = null; DebugOutput("**** IOConnect.Dispose(bool) for " + GetType() + " called IOServerClose, RetainCount: " + NativeMethods.IOObjectGetUserRetainCount(handle)); } }