dskit
dskit copied to clipboard
Presenting and then dismissing leads to memory leak
Describe the bug
Presenting and then dismissing a DSViewController embedded to a UINavigationController (or DSNavigationViewController, does not matter) leads to memory leak.
To Reproduce I could reproduce this issue also in the DSKitExplorer project with the following steps:
- Added a button to
ShowContentVC:
...
let button = DSButtonVM(title: "Let's do it!") { [weak self] (_: DSButtonVM) in
self?.presentInNavigationController(vc: ShowTopContentVC())
//self?.present(UINavigationController(rootViewController: ShowTopContentVC()), animated: true)
}
show(content: [viewModels.list(), button.list()])
...
- Added button to
ShowTopContentVCto be able to dismiss itself:
...
let button = DSButtonVM(title: "Go away!") { [weak self] (_: DSButtonVM) in
self?.dismiss()
}
show(content: [viewModels.list(), button.list()])
...
- Also added
deinitmethod toShowTopContentVCto see whether it is deallocated or not:
deinit {
print("Deinitalizing of \(self)")
}
Expected behavior
ShowTopContentVC is deallocated right after dismissing.
To ensure this happens, console should print something like this:
Deinitalizing of <DSKitExplorer.ShowTopContentVC: 0x13189d200>
Additional context
- To the 1. reproduction point: I've also tried to present
ShowTopContentVCembedded into aUINavigationControllerinstead of aDSNavigationViewControllerbut the result is the same in both cases. - When presenting and dismissing a single
DSViewControllerwithout embedding it into a navigation controller, then everything works as expected, the view controller is deallocated as expected. - I've found (very probably) the root of the problem but I don't really went deeper and don't have a fully understand how things work under the hood
- when I comment out this line in
DSBaseViewController, everything works as expected,ShowTopContentVCis deinitalized right after dismiss:
- when I comment out this line in
override open func viewDidLoad() {
super.viewDidLoad()
// DSAppearance.shared.appearancePublisher.subscribe(self)
setUpLargeTitleDisplayMode()
setUpProgressHud()
setUpMessageHud()
updateAppearance()
showNavigationBarShadow()
}
Screenshots
As you can see I've presented and dismissed ShowTopContentVC several times and all the instances are still in the memory.
Could you please check this issue? Thank you in advance for your reply!