In our current app we need to perform some cleanup in the Dispose() of our custom UITableViewCells.
Unfortunately even though we call TableView.Dispose() our cells won't immediately get disposed. Instead, later on, the finalizer will call Dispose(false). Since we are called by the finalizer we shouldn't perform our cleanup here: objects might be in a unpredictable state and the time when it occurs can't be determined.
From Microsoft documentation:
The finalizer is called when the GC detects that an object is eligible for collection. This happens at some undetermined period of time after the resource is not needed anymore.
And also:
If the method is invoked from the finalizer (disposing is false), other objects should not be accessed. The reason is that objects are finalized in an unpredictable order and so they, or any of their dependencies, might already have been finalized.
Is there a solution to have the Dispose() method of our custom cells be called when the tableview is disposed?