“Do you remember what happens to the UIKit presentingViewController
of a modally presented VC? Its view is removed from the hierarchy, as long as the presentedViewController
is on the screen (another very good engineering approach: don't keep it around if you don't need it
).”
Ummm… that’s not how that works. A UINavigation hierarchy is a stack of UIViewControllers. Pushing a new UIViewController adds another one to the stack. Presenting a new UINavigationController/UIViewController adds another layer to that hierarchy, but the prior hierarchy and view controller stack still exists.
This is even more apparent in iOS 13, where the default UINavigation presentation behavior is NOT to cover the full screen, leaving the previous navigation stack in view.
You can also trace this behavior in UIKit by following the UIViewController lifecycle. Present a UIViewController and the presenting controller gets a viewWillDisappear, viewDidDisappear pair. Dismiss the presented controller, and the presenting controller gets a viewWillAppear, viewDidAppear pair.
It does NOT get a viewDidLoad event in that sequence, which in most cases would be required to recreate the presenting view controller. Nor does is it prompted to serialize/deserialize its state.
If that’s not enough, then add some deinits to your VCs to track ’em. Assuming no retain cycles, they’ll go away when popped or dismissed, and not before. Nope, the resources persist.