Reputation: 121
In UIViewController
deinit
method not calling in ios swift4.2
I have tried below code for navigate to next viewController
after navigation in popToViewcontroller
deinit
method not calling.
let data = isSearchEnabled ? repository.filteredList[index] : repository.list[index]
let appDelegate = UIApplication.shared.delegate as! AppDelegate
(appDelegate.window?.rootViewController as! UITabBarController).tabBar.isHidden = true
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "AuctionDetailsViewController") as! AuctionDetailsViewController
viewController.auction = data.getAuctionData()
viewController.parentVC = self
parentNavigationController?.pushViewController(viewController, animated: true)
PushView :
deinit {
print("AuctionDetailsViewController deallocated...")
}
The above deinit
method should be call on popToViewcontroller
Upvotes: 2
Views: 4519
Reputation: 8914
You need to aware about the memory management done ay iOS using ARC. You can read this here
Deinit() is not called, if viewcontoller...
holds the strong reference of an object(retain cycle)
you need to check and remove the unnecessary strong references to an object to avoid retail cycle
has notification observer
you need to unregister an observer because the notification center retains the observer until you unregister it.
uses of delegates (hold the strong reference of it)
if view controller is confirming the protocol that delegate should be marked as
weak
.
The above mentioned are the some points that prevents the view controller to dealloc and deinit is never called. There may be other points reason too for the same.
Upvotes: 2