I have the following view hierarchy in my app: [UINavigationController] -> [MainViewController] -> [MyTabBarController] -> [DashboardViewController]
In my MainViewController I have a button that pushes the MyTabBarController onto the navigation controllers stack. In the tab bar controller I only have one tab in this example showing the DashboardViewController.
That all works fine, and when I tap the back button on MyTabBarController, everything works fine and the MainViewController is shown again. The UI works exactly how I want it, but when I load up the 'Debug Memory Graph' view, I can see that my DashboardViewController is still in memory and it seems the UITab has a reference to it. The MyTabBarController is NOT in memory anymore.
MyTabBarController is very simple:
class MyTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
self.mode = .tabSidebar
var allTabs:[UITab] = []
let mainTab = UITab(title: "Dashboard",
image: UIImage(systemName: "chart.pie"),
identifier: "dashboard",
viewControllerProvider: { _ in
return UINavigationController(rootViewController: DashboardViewController())
})
allTabs.append(mainTab)
setTabs(allTabs, animated: false)
}
}
And the DashboardViewController is empty:
class DashboardViewController: UIViewController {
}
The only reason I created as a seperate class in this example is so I can easily see if it's visible in the memory debug view.
I have uploaded the simple sample app to GitHub: https://github.com/fwaddle/TabbarMemoryLeakCheck
Anyone have any suggestions?
Here is a screen grab of the memory debug view showing the UITab having a reference to the DashboardViewController even though MyTabBarController has been dealloc'd: