In a controller we have added observer in viewDidAppear
and it's removed in viewWillDisappear
. There is no observer in init/viewDidLoad
.
In such a case the below line for safety purpose/is it required in dealloc
method?
[[NSNotificationCenter defaultCenter] removeObserver:self];
Now the question/doubt is are there scenarios where dealloc
will get called without viewWillDisappear
not being called? What about when memory warnings are called. What happens in those cases?
Thanks.
One scenario is:
VC1
implements the class HelperVC
, it's delegates and added HelperVC
as it's subview.HelperVC
calls closeAll
delegate method, which is implemented in VC1
.closeAll
method in VC1
sets the HelperVC
object to nil
.dealloc
method is called in HelperVC
instead of viewWillDisappear
. Because we didn’t remove the HelperVC
view, we have made HelperVC
object to nil
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With