Reputation: 149
I know it's all with the weak strong reference when presenting the viewController in the parent view ... correct me please if I'm wrong
this is an example how I do it
let viewHolder = viewClass()
func presentView() {
self.present(viewHolder, animated: true) {
}
}
see my memory monitor only from open and dismiss the same view over and over
weak var viewHolder = viewClass()
func presentView() {
self.present(viewHolder!, animated: true) {
}
}
but this would give me a crash
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
and dismiss the viewClass this way (inside itself off)
func dismissPage() {
self.dismiss(animated: true)
}
any help would be appreciated thanks
Upvotes: 0
Views: 2157
Reputation: 41
Use deint method and check weather it is called or not after dismiss your viewcontroller.
if your using any kind of blocks or closure to work done then use [weak self] in side your closure.
Upvotes: 1
Reputation: 910
The problem might not be in the viewClass
. You are declaring let viewHolder = viewClass()
in your initial class. So when you dismiss the controller, that variable still exists. Do you need to keep a reference to it? If not, you can easily allocate it when needs to be displayed and when you dismiss it, the memory is going to be freed:
func presentView() {
// instead of saving viewHolder as an instance variable, you declare it locally
let viewHolder = viewClass()
self.present(viewHolder, animated: true) {
}
}
Upvotes: 1