Most of my UIKit Dispose
overrides do something with other views before they get destroyed:
protected override void Dispose (bool disposing)
{
if (ScrollView != null) {
ScrollView.RemoveObserver (this, new NSString ("contentOffset"));
ScrollView.RemoveObserver (this, new NSString ("contentInset"));
ScrollView = null;
}
base.Dispose (disposing);
}
I just recently realized that Dispose
will run on finalizer thread if disposing
is true
.
In this case ScrollView.RemoveObserver
will be called from non-UI thread which is Bad.
What's the safe way to do UIKit-related cleanup in Dispose
?
This question was originally posted on StackOverflow.