Doubt about the dealloc overriding


#1

I know WhereamiViewController does not get dealloc, but if it hypothetically did, wouldn’t overriding dealloc be pointless, since locationManager would get dealloc too? I believe it wouldn’t be preventing any errors since locationManager would disappear and wouldn’t be able to send messages to its now non-existent delegate.

Please clear my doubt! Thanks! :slight_smile:


#2

So all objects get sent dealloc when they are destroyed, it is just that you don’t typically have to implement any code because destruction is automatic. (For the most part.)

In this case, yeah, the object locationManager points at will get destroyed, too. However, if this application grew or you changed in some way, it is possible that another object could add a strong reference to that CLLocationManager which would allow it to live longer than its delegate. Clearing the delegate here makes so that no matter how long the location manager lives, it will never send a message to a destroyed WhereamiViewController.